英文:
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
的标题,它在右边更可见,但整个东西太大了):
我已将<Content>
修改为<Resource>
标签:
<Resource Include="Pictures\Coldstart.png" >
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
这要好得多,但图片太大了。图片或RadRibbonButton
是否有“自动调整大小”的选项?
目前的外观如下(不完整的图片,不再有空间容纳文本):
英文:
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:
<Project ToolsVersion="14.0"
DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
...
<ItemGroup>
<Content Include="ThisProject.ico" />
<Content Include="Pictures\Coldstart.png" />
...
...
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):
I have modified the <Content>
into a <Resource>
tag:
<Resource Include="Pictures\Coldstart.png" >
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
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):
答案1
得分: 1
请看以下翻译:
代替 Content
<Content Include="Pictures\Coldstart.png" />
使用 Resource
<Resource Include="Pictures\Coldstart.png" />
考虑将您图片目录中的所有文件声明为资源,使用以下代码
<Resource Include="Pictures\**\*.*" />
(注意:这还包括所有子目录)
英文:
Instead of Content
<Content Include="Pictures\Coldstart.png" />
use Resource
<Resource Include="Pictures\Coldstart.png" />
consider declaring all files as resource in your pictures directory with this
<Resource Include="Pictures\**\*.*" />
(notice: this also includes all sub directories)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论