【发布时间】:2010-03-12 20:19:03
【问题描述】:
有问题的图像位于 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 中查看控件时,图像显示得很好,但是当我运行应用程序时,图像不显示。如果我将相同的图像放入 UserControl 中,它也显示得很好,所以问题与使用模板有关。
还有其他方法可以在模板中加载图像资源吗?
【问题讨论】:
-
我最终做的是制作一个新的用户控件,它基本上是一个图像控件的包装器。它有一个属性“Source”,它只是包装的 Image 控件的“Source”属性的传递。从模板中使用这个包装器控件就可以了。
标签: silverlight image controltemplate resourcedictionary