开发者

Add style to a Data template

I have the following Data template with triggers:

    <DataTemplate.Triggers>
        <DataTrigger Binding="{Binding IsCalled}" Value="Yes">
            <Setter TargetName="labelNumber" Property="Background" Value="Green" />
            <Setter TargetName="labelNumber" Property="BorderThickness" Value="5" />
            <Setter TargetName="labelNumber" Property="BorderBrush" Value="Blue" />
        </DataTrigger>
        <DataTrigger Binding="{Binding IsCalled}" Value="JustCalled" >
            <Setter TargetName="labelNumber" Property="Background" Value="Pink" />
       </DataTrigger>
    </DataTemplate.Triggers>

</DataTemplate>

Rather than individually set the label properties I want to call a style like the below:

开发者_如何转开发

How would get the Data Template to use the style above.

thank you


You can use a setter like

<Setter TargetName="labelNumber" Property="Style" Value="{StaticResource myLabelStyle1}" />

but you'll need to make sure you're not setting any properties locally on the labelNumber Label because they'll override any Style settings. You'll need another Style for your Label to set any properties for its default state in addition to the ones in the Triggers.

<Label Style="{StaticResource myDefaultLabelStateStyle}"/>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜