I defined a style in a ResourceDictionary
for a button with an image:
<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>
The image source is defined in another ResourceDictionary
in the same assembly, and marked as x:Shared="False"
:
<BitmapImage x:Key="IconoDashboardBlanco" x:Shared="False"
UriSource="pack://application:,,,/QualityFramework;component/Images/dashboard64X64.png"/>
Since the style will be used in a different assembly, I used the "pack://application:,,,"
notation to reference the image. The Build Action
for the image is set to Resource (Do not copy to output directory)
.
In the main assembly I have two UserControls
which display a button with identical style:
<Button DockPanel.Dock="Left" Style="{StaticResource BotonIrAInicioStyle}" Click="BotonIrAInicio_Click"/> (Click event has nothing to do with the problem)
PROBLEM:
I open UserControl A
containing the button with the image and the image is displayed ok. Then I open UserControl B
containing an identical button, image ok. I open UserControl A
again, and the image is gone. Happens the same if I open UserControl B
and then UserControl A
, the last one "owns" the image.
I went everywhere and all the solutions point to the x:Shared="False"
, the URI notation
and the Build Action
... I applied all of them and the problem still happens. I also tried cleaning and rebuilding with no success.
What am I missing? Thanks!
PS: if I set the content of both buttons to the image directly it works ok, but the whole point of styling is to avoid exactly that!