为什么我无法在我的Telerik按钮上看到图像?

huangapple go评论63阅读模式
英文:

Why can't I see the image on my Telerik button

问题

以下是翻译好的部分:

这是我 C# 程序中的一个 xaml 文件的一部分:

<telerik:RadRibbonGroup Header="General/Tests">
    <StackPanel Orientation="Horizontal">
        <telerik:RadRibbonButton Command="{Binding Path=...}" Style="{StaticResource RibbonTabButton}">
            <StackPanel Orientation="Vertical">
                <Image Source="/ThisProject;component/Pictures/Coldstart.png" />
                <TextBlock Text="Coldstart all zones" TextAlignment="Center"/>
            </StackPanel>
        </telerik:RadRibbonButton>
    </StackPanel>
</telerik:RadRibbonGroup>

我通过从解决方案资源管理器拖动文件名将"<Image Source ..."代码片段添加到了xaml文件中,但在运行代码时看不到任何东西。XAML 设计器工作不正常,所以我需要运行项目以查看是否有效。

*.csproj文件中,我已经将提到的*.png文件添加到项目中,如下所示:

<Project ToolsVersion="14.0" 
         DefaultTargets="Build" 
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
...
  <ItemGroup>
    <Content Include="ThisProject.ico" />
    <Content Include="Pictures\Coldstart.png" />
    ...
  ...

为什么我看不到图片,只看到“Coldstart”按钮的文本?我需要执行任何操作(如“图像导入”)才能使其工作吗?

请注意,这是它的外观(不要担心看不到RadRibbonGroup的标题,它在右边更可见,但整个东西太大了):

为什么我无法在我的Telerik按钮上看到图像?

我已将<Content>修改为<Resource>标签:

<Resource Include="Pictures\Coldstart.png" >
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>

这要好得多,但图片太大了。图片或RadRibbonButton是否有“自动调整大小”的选项?

目前的外观如下(不完整的图片,不再有空间容纳文本):

为什么我无法在我的Telerik按钮上看到图像?

英文:

This is a part of a xaml file in my C# program:

<telerik:RadRibbonGroup Header="General/Tests">
    <StackPanel Orientation="Horizontal">
        <telerik:RadRibbonButton Command="{Binding Path=...}" Style="{StaticResource RibbonTabButton}">
            <StackPanel Orientation="Vertical">
                <Image Source="/ThisProject;component/Pictures/Coldstart.png" />
                <TextBlock Text="Coldstart all zones" TextAlignment="Center"/>
            </StackPanel>
        </telerik:RadRibbonButton>
    </StackPanel>
</telerik:RadRibbonGroup>

I have added the "<Image Source ..." piece of source code by dragging that filename from the Solution explorer into the xaml file, yet I don't see anything when I run the code. The XAML designer is not working properly, so I need to run the project in order to see if it works.

That mentioned *.png file is something I have added to my project, it looks as follows in the *.csproj file:

&lt;Project ToolsVersion=&quot;14.0&quot; 
         DefaultTargets=&quot;Build&quot; 
         xmlns=&quot;http://schemas.microsoft.com/developer/msbuild/2003&quot;&gt;
...
  &lt;ItemGroup&gt;
    &lt;Content Include=&quot;ThisProject.ico&quot; /&gt;
    &lt;Content Include=&quot;Pictures\Coldstart.png&quot; /&gt;
    ...
  ...

Why don't I see the picture, but only the text of the "Coldstart" button? Do I need to do any action (like an "image import") to make this work?

For your information, this is what is looks like (don't worry about not seeing the header of the RadRibbonGroup, it is visible more to the right but the entire thing is too large):

为什么我无法在我的Telerik按钮上看到图像?

I have modified the &lt;Content&gt; into a &lt;Resource&gt; tag:

&lt;Resource Include=&quot;Pictures\Coldstart.png&quot; &gt;
  &lt;CopyToOutputDirectory&gt;PreserveNewest&lt;/CopyToOutputDirectory&gt;
&lt;/Resource&gt;

This is A LOT better, but the image is too large. Is there an "AutoResize" option to the image or to the RadRibbonButton?

It currently looks as follows (incomplete image and no room for the text anymore):

为什么我无法在我的Telerik按钮上看到图像?

答案1

得分: 1

请看以下翻译:

代替 Content

&lt;Content Include=&quot;Pictures\Coldstart.png&quot; /&gt;

使用 Resource

&lt;Resource Include=&quot;Pictures\Coldstart.png&quot; /&gt;

考虑将您图片目录中的所有文件声明为资源,使用以下代码

&lt;Resource Include=&quot;Pictures\**\*.*&quot; /&gt;

(注意:这还包括所有子目录)

英文:

Instead of Content

&lt;Content Include=&quot;Pictures\Coldstart.png&quot; /&gt;

use Resource

&lt;Resource Include=&quot;Pictures\Coldstart.png&quot; /&gt;

consider declaring all files as resource in your pictures directory with this

&lt;Resource Include=&quot;Pictures\**\*.*&quot; /&gt; 

(notice: this also includes all sub directories)

huangapple
  • 本文由 发表于 2023年5月11日 16:54:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76225809.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定