开发者

How to use MultiDataTrigger to check a single condition to be true in Style.Triggers in WPF?

开发者 https://www.devze.com 2022-12-18 11:55 出处:网络
I have three grids in my UserControl of which one control is shown at time. In the last column I need to use a Style where I need to check the data and apply a ForeGround color. I can write style at e

I have three grids in my UserControl of which one control is shown at time. In the last column I need to use a Style where I need to check the data and apply a ForeGround color. I can write style at each of the control in 3 grids using DataTriggers. But I want a concrete style in Resource which can be used anywhere. I tried MultiDataTrigger bu开发者_如何学运维t it doesn't serve my purpose as it checks 2 or more Condintions to be true in MultiDataTrigger.Conditions whereas i need to check data in a single control. Are there any alternate solution to achieve this?


If you're using some kind of a grid, you're probably using CellTemplate or some other property like that to accomplish your task. I think you do need to use different styles in different columns.

But if those styles are the same except for the triggers, then you can make one style with everything that's common to both of them, and then create another style based on the first one. It's a bit similar to inheritance in OOP.

This is how it may look like:

<Style x:Key="BaseStyle" TargetType=".....">
    <!-- Common setters and triggers -->
    <Setter ... />
    <Setter ... />
    <Setter ... />
</Style>

<Style x:Key="InheritedStyle" BasedOn="{StaticResource BaseStyle}" TargetType=".....">
    <!-- This style's specific setters and triggers -->
    <Setter ... />
    <Style.Triggers>
    ...
    <Style.Triggers>
</Style>
0

精彩评论

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