【问题标题】:Image shows in Expression Blend but not during runtime图像在 Expression Blend 中显示,但在运行时不显示
【发布时间】: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


【解决方案1】:

我认为您不需要前导“/”。我用于项目的基本资源路径是 SL 3 和 4 中的“IMLPrototype2;component/Model/Sounds/”。

【讨论】:

  • 我试过不带前导'/'。它仍然没有显示。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-07
  • 2012-03-01
  • 2016-02-09
  • 2018-01-18
相关资源
最近更新 更多