How could I change the Canvas.Zindex of an object using visual states? I was expecting to be able to do something like this..
<VisualState x:Name="MyVisualState">
<VisualState.Setters>
<Setter Target="MyObject.Visibility" Value="Visible" />
<Setter Target="MyObject.Background" Value="Transparent" />
<Setter Target="MyObject.Canvas.ZIndex" Value="12" />
</VisualState.Setters>
</VisualState>
But this does not work. I have not been able to find any examples on how to do this. Can someone help?
Here you go. Note you need the ()
there because Canvas.ZIndex
is an attached property and that's how you define the value of it in XAML.
<VisualState x:Name="MyVisualState">
<VisualState.Setters>
<Setter Target="MyObject.Visibility"
Value="Visible" />
<Setter Target="MyObject.Background"
Value="Transparent" />
<Setter Target="MyObject.(Canvas.ZIndex)"
Value="12" />
</VisualState.Setters>
</VisualState>
You might be interested in this answer which will show you how to generate the code above without writing a single line of code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With