图像在 Expression Blend 中显示,但在运行时不显示
有问题的图像位于 ResourceDictionary 内的 ControlTemplate 中,与此类似(为了清晰起见,删除了各种细节):
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
<ControlTemplate x:Key="ImageTestTemplate" TargetType="ImageTest">
<Grid>
<Image Source="/MyAssembly;Component/Images/MyImage.png"/>
</Grid>
</ControlTemplate>
</ResourceDictionary>
当我在 Expression Blend 中查看控件时,图像显示得很好,但当我运行应用程序时,图像不显示向上。如果我将相同的图像放入用户控件中,它也会显示得很好,因此问题与使用模板有关。
我是否应该通过其他方式在模板中加载图像资源?
The image in question is located in a ControlTemplate inside of a ResourceDictionary similar to this (various details removed for clarity):
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
<ControlTemplate x:Key="ImageTestTemplate" TargetType="ImageTest">
<Grid>
<Image Source="/MyAssembly;Component/Images/MyImage.png"/>
</Grid>
</ControlTemplate>
</ResourceDictionary>
When I view the control in Expression Blend the image shows up just fine, but when I run the app the image does not show up. If I drop the same image into a UserControl it also shows up just fine, so the problem has something to do with using the template.
Is there some other way I should be loading the image resource inside the template?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您不需要领先的“/”。我用于项目的基本资源路径是 SL 3 和 SL 中的“IMLPrototype2;component/Model/Sounds/”。 4.
I don't think you need the leading '/'. The base resource path I'm using for a project is "IMLPrototype2;component/Model/Sounds/" in SL 3 & 4.