Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I change the Canvas.Zindex of an object using visual states?

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?

like image 294
Gema Beltran Avatar asked Mar 08 '23 02:03

Gema Beltran


1 Answers

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.

like image 106
Justin XL Avatar answered Mar 10 '23 15:03

Justin XL