开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜