简体   繁体   中英

DataTrigger / Style quick in XAML

I have an Ellipse defined as so

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

I also have two styles setup like so

<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, when the Ellipse is first drawn it is Red as per the RedGradientBrush. I want to make the ellipse green when a binded value (Selected) is true so I added a Style to do 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, when Selected is True ONLY the StrokeThickness changes, nothing else? Can anyone help please?

Thanks

Apparently XAML inline styles override any you set. This is why only the StrokeThickness was being changed as it wasn't set inline.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM