DataTrigger / Style fast in XAML

I have an ellipse defined as

<Ellipse Stroke="#FF474747" Style="{StaticResource SelectedTemplate}" Fill="{StaticResource RedGradient}" />

I also have two style settings:

<RadialGradientBrush x:Key="RedGradient" GradientOrigin="1,1">
    <GradientStop Color="White"/>
    <GradientStop Color="Red" Offset="1"/>
</RadialGradientBrush>

<RadialGradientBrush x:Key="GreenGradient" GradientOrigin="1,1">
    <GradientStop Color="White"/>
    <GradientStop Color="Green" Offset="1"/>
</RadialGradientBrush>

Now that the ellipse is first drawn, it is red according to RedGradientBrush. I want to make the ellipse green when the bound value (Selected) is true, so I added a style for this

<Style x:Key="SelectedTemplate" TargetType="Ellipse">
    <Style.Triggers>
        <DataTrigger Value="True" Binding="{Binding Selected}">
            <Setter Property="Stroke" Value="White" />
            <Setter Property="StrokeThickness" Value="5" />
            <Setter Property="Fill" Value="{StaticResource GreenGradient}" />
        </DataTrigger>
    </Style.Triggers>
</Style>

Now that Selected is True ONLY, StrokeThickness is changing, nothing more? Can anyone help?

thanks

+3
source share
1 answer

XAML inline styles seem to override any ones you set. That is why only StrokeThickness has changed since it was not installed in a row.

+2
source

Source: https://habr.com/ru/post/1724484/


All Articles