4

I'm trying to write a VisualState for my new Universal app under Windows 10.
According to the documentation about VisualState.StateTriggers, you can add multiple triggers to a visual state, as the property is of type IList<StateTriggerBase>.

The VisualState class documentation also points out to the StateTriggers documentation:

oneOrMoreTriggers

One or more triggers that can be an AdaptiveTrigger or a custom trigger derived from StateTriggerBase. These can be used to indicate when the corresponding VisualState needs to be applied automatically without an explicit GoToState call. See Remarks on the StateTriggers property for more info.

However, the documentation doesn't point out how multiple triggers work here. Neither is there a way to modify the behavior by any C# code.
My desired behavior would require some AND/OR conditions for those trigger specified in the StateTriggers section.

Is there any other way, than writing my own "MultiTrigger", deriving from StateTriggerBase?

Community
  • 1
  • 1
Stefan Over
  • 5,851
  • 2
  • 35
  • 61

3 Answers3

5

Ok. As there is no built in MultiTrigger, I wrote my own MultiTrigger. The multi trigger supports AND and OR conditions, which is exactly what I needed.

It is now included in the NuGet Package AdaptiveTriggerLibrary.

Stefan Over
  • 5,851
  • 2
  • 35
  • 61
  • I've installed the AdaptiveTriggerLibrary in my UWP project (built for RS1) and I'm trying to get two MultiTriggers with an AndModifier working with a WindowHeightTrigger and a WindowWidthTrigger each, but it seems that the first MultiTrigger is always active over the second one no matter what I do. Do you have a support email for that library, where can I get some help about it? Thanks! – Sergio0694 Sep 16 '16 at 00:21
  • @Sergio0694 Feel free to open an issue on GitHub: https://github.com/Herdo/AdaptiveTriggerLibrary - I'll look into it, as soon as possible. – Stefan Over Sep 16 '16 at 15:12
-1

Herdo, What I have observed in the StateTriggers behaviors is that when triggers are in the same group they are executed in a mutually exclusive way in order, sort of the AND mode. AND triggers from different VisualStateGroups execute independently, sort of the OR mode. In this observed behavior, I organize things that change the same set of properties into the same group, so that the condition is controlled inside the group.

Milo
  • 3,365
  • 9
  • 30
  • 44
-2

Try using distinct VisualStateGroups. For example to handle different widths and orientations use 2 VisualStateGroups

<VisualStateGroups x:Name="WidthStates">
    ...
</VisualStateGroups> 

<VisualStateGroups x:Name="OrientationStates">
    ...
</VisualStateGroups> 

view this related question on msdn:

https://social.msdn.microsoft.com/Forums/sqlserver/en-US/95291be1-25c7-4310-bb2b-b8fcead3b4d9/multiple-statetriggers-supporting-narrow-and-landscape

Alberto Rivelli
  • 1,953
  • 2
  • 15
  • 19