I have a scenario. I have my custom vector logo which I defined in separate xaml file MyLogo.xaml. I also added default fill color.
now when I run my app, I want to change it's color depending on enum value, but somehow it does not change... Can someone please help me?
this is the xaml of my logo and triggers declaration:
<misc:MyLogo
DockPanel.Dock="Top"
Height="200"
Margin="0 30 0 0">
<misc:MyLogo.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding MyEnum}" Value="{x:Static enum:MyEnum.ValueOne}">
<Setter Property="Path.Fill" Value="#FFFFFF" />
</DataTrigger>
<DataTrigger Binding="{Binding MyEnum}" Value="{x:Static enum:MyEnum.ValueTwo}">
<Setter Property="Path.Fill" Value="#000000" />
</DataTrigger>
</Style.Triggers>
</Style>
</misc:MyLogo.Style>
</misc:MyLogo>
If it helps I'm using Caliburn Micro. So please can you tell me where is the bug, o what kind of workaround are there?
I tried How to change a path fill (on a button) with triggers in XAML solution but it didn't helped...
UPDATE 1
MyLogo.xaml
As you can see Path has it's default Fill value:
<Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Stretch="Uniform">
<Canvas Name="svg4" Width="10" Height="9">
<Canvas.RenderTransform>
<TranslateTransform X="0" Y="0"/>
</Canvas.RenderTransform>
<Canvas.Resources/>
<Path xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="path2" Fill="#FFFFFFFF">
<Path.Data>
<PathGeometry Figures="M10 4.194v.612H1.195L5.049 8.57l-.44.43L0 4.5 4.608 0l.441.43-3.854 3.764z" FillRule="EvenOdd"/>
</Path.Data>
</Path>
</Canvas>
</Viewbox>
UPDATE 2 (PROBLEM ANSWER) After some research i finally managed to fix my problem... So if anyone will face this, the simplest solution is this:
As in comments some users wrote me that I should remove Viewbox and Canvas elements from my xaml then you can leave it (in my scenario it is auto generated xaml file from svg if it's generated then it should be valid like it is)
To change the color of my logo, I had to create Dependency Property for my xaml. It looks like this:
public partial class MyLogo: UserControl { public static readonly DependencyProperty BackgroundFillProperty = DependencyProperty.Register("BackgroundFill", typeof(SolidColorBrush), typeof(MyLogo), new PropertyMetadata(new SolidColorBrush())); public MyLogo() => InitializeComponent(); public SolidColorBrush BackgroundFill { get => (SolidColorBrush)GetValue(BackgroundFillProperty); set => SetValue(BackgroundFillProperty, value); }
}
Then in MyLogo.xaml I changed my Fill property with the following:
Fill="{Binding BackgroundFill, RelativeSource={RelativeSource AncestorType=UserControl}}"
and finally in my view where the triggers are, I changed setters to this:
<Setter Property="misc:MyLogo.BackgroundFill" Value="#ffffff" />
And that's it.. Hope someone will find this useful :)