1

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 but 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?

Anatoliy Nikolaev
  • 22,370
  • 15
  • 69
  • 68
munna
  • 11
  • 1

1 Answers1

1

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>
arconaut
  • 3,227
  • 2
  • 27
  • 36