我在a中定义了一个样式ResourceDictionary
对于带有图像的按钮:
<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)
PROBLEM:
I open UserControl A
包含带有图像的按钮并且图像显示正常。然后我打开UserControl B
包含相同的按钮,图像正常。我打开UserControl A
再次,图像就消失了。如果我打开也会发生同样的情况UserControl B
进而UserControl A
,最后一个“拥有”该图像。
我到处走走,所有的解决方案都指向x:Shared="False"
, the URI notation
和Build Action
...我都应用了,问题仍然发生。我也尝试过清理和重建,但没有成功。
我缺少什么?谢谢!
PS:如果我将两个按钮的内容直接设置为图像,则可以正常工作,但样式的全部要点就是避免这种情况!