ResourceDictionary我在 a中为带有图像的按钮定义了一种样式:
<Style x:Key="BotonIrAInicioStyle" TargetType="Button">
<Setter Property="Margin" Value="0"/>
<Setter Property="Width" Value="{Binding RelativeSource={RelativeSource Self}, Path=ActualHeight}"/>
<Setter Property="Content">
<Setter.Value>
<Image Margin="2" Source="{StaticResource IconoDashboardBlanco}" MaxHeight="20" Stretch="Uniform"
RenderOptions.BitmapScalingMode="HighQuality"/>
</Setter.Value>
</Setter>
</Style>
图像源ResourceDictionary在同一程序集中的另一个中定义,并标记为x:Shared="False":
<BitmapImage x:Key="IconoDashboardBlanco" x:Shared="False"
UriSource="pack://application:,,,/QualityFramework;component/Images/dashboard64X64.png"/>
由于样式将在不同的程序集中使用,因此我使用"pack://application:,,,"符号来引用图像。图像的Build Action设置为Resource (Do not copy to output directory)。
在主程序集中,我有两个UserControls显示具有相同样式的按钮:
<Button DockPanel.Dock="Left" Style="{StaticResource BotonIrAInicioStyle}" Click="BotonIrAInicio_Click"/> (Click event has nothing to do with the problem)
问题:
我打开UserControl A包含带有图像的按钮,图像显示正常。然后我打开UserControl B包含一个相同的按钮,图像确定。我UserControl A再次打开,图像消失了。UserControl B如果我打开然后UserControl A,最后一个“拥有”图像,也会发生同样的情况。
我到处都是,所有的解决方案都指向x:Shared="False", theURI notation和Build Action... 我应用了所有这些,但问题仍然存在。我也尝试过清洁和重建,但没有成功。
我错过了什么?谢谢!
PS:如果我将两个按钮的内容直接设置为图像,它可以正常工作,但造型的重点是要避免这种情况!