1

我有一个自定义控件库,其中包含一个引用同一自定义控件库中的图像的资源字典。

然后,我有一个 WPF 应用程序,其中引用了自定义控件库,其中包含一个资源字典,其样式使用图像。

当我尝试使用来自外部资源的样式时,我收到一条错误消息,告诉我找不到样式中引用的图像。

我有一个示例解决方案,我可以发送给任何需要它的人,但我希望那里有人知道答案......

谢谢,亚伦

4

2 回答 2

2

Ok, this is what I found... If you have an external resouce dictionary with a style:

<Style x:Key="Arrow" TargetType="{x:Type Button}">
<Setter Property="Template">
  <Setter.Value>
    <ControlTemplate TargetType="{x:Type Button}">
      <StackPanel Orientation="Horizontal" Width="Auto" Height="20">
        <Image Source="/Images/RightArrow.png" />
      </StackPanel>
    </ControlTemplate>
  </Setter.Value>
</Setter>

and the image is in the Images folder of the external assembly the above source reference works just fine when you are in your development environment, but once you reference the assembly the relative path to the RightArrow.png is lost to the referencing WPF App. So the answer is to use the following for the source:

        <Image Source="/Skin;component/Images/RightArrow.png" />

Note the pick URI instead of the relative path. This assures that the referencing application knows where to really find the image.

于 2009-06-09T20:40:18.683 回答
0

当您将图像添加到 VS 中的项目时,它有一个名为“复制到输出目录”的属性。将其值设置为“始终复制”或“如果较新则复制”。然后重建。我敢打赌,它会修复它。

于 2009-06-09T20:12:36.053 回答