Я работаю над приложением UWP и пытаюсь реализовать методологию MVVM.В основном я пытаюсь запустить раскадровку, когда значение привязки изменяется во время выполнения.
До сих пор я придумал следующее:
<UserControl
...
xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
xmlns:Media="using:Microsoft.Xaml.Interactions.Media">
<UserControl.Resources>
<Storyboard x:Name="cValueSB" AutoReverse="True" RepeatBehavior="3">
<DoubleAnimation To="0" Duration="0:0:0.5" Storyboard.TargetName="cvalue" Storyboard.TargetProperty="(UIElement.Opacity)"/>
</Storyboard>
<Storyboard x:Name="hValueSB" AutoReverse="True" RepeatBehavior="3">
<DoubleAnimation To="0" Duration="0:0:0.5" Storyboard.TargetName="hvalue" Storyboard.TargetProperty="(UIElement.Opacity)"/>
</Storyboard>
<Storyboard x:Name="lValueSB" AutoReverse="True" RepeatBehavior="3">
<DoubleAnimation To="0" Duration="0:0:0.5" Storyboard.TargetName="lvalue" Storyboard.TargetProperty="(UIElement.Opacity)"/>
</Storyboard>
<Storyboard x:Name="nValueSB" AutoReverse="True" RepeatBehavior="3">
<DoubleAnimation To="0" Duration="0:0:0.5" Storyboard.TargetName="nvalue" Storyboard.TargetProperty="(UIElement.Opacity)"/>
</Storyboard>
</UserControl.Resources>
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="large">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="{StaticResource ScreenWidthSixForty}"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="cvalue.(Grid.Row)" Value="1"/>
<Setter Target="hvalue.(Grid.Row)" Value="1"/>
<Setter Target="lvalue.(Grid.Row)" Value="1"/>
<Setter Target="nvalue.(Grid.Row)" Value="1"/>
<Setter Target="cvalue.(Grid.Column)" Value="0"/>
<Setter Target="hvalue.(Grid.Column)" Value="1"/>
<Setter Target="lvalue.(Grid.Column)" Value="2"/>
<Setter Target="nvalue.(Grid.Column)" Value="3"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="middle">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="{StaticResource ScreenWidthThreeSixty}"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="cvalue.(Grid.Row)" Value="1"/>
<Setter Target="hvalue.(Grid.Row)" Value="2"/>
<Setter Target="lvalue.(Grid.Row)" Value="1"/>
<Setter Target="nvalue.(Grid.Row)" Value="2"/>
<Setter Target="cvalue.HorizontalAlignment" Value="Right"/>
<Setter Target="hvalue.HorizontalAlignment" Value="Right"/>
<Setter Target="lvalue.HorizontalAlignment" Value="Right"/>
<Setter Target="nvalue.HorizontalAlignment" Value="Right"/>
<Setter Target="cvalue.(Grid.ColumnSpan)" Value="2"/>
<Setter Target="hvalue.(Grid.ColumnSpan)" Value="2"/>
<Setter Target="lvalue.(Grid.Column)" Value="2"/>
<Setter Target="nvalue.(Grid.Column)" Value="2"/>
<Setter Target="lvalue.(Grid.ColumnSpan)" Value="2"/>
<Setter Target="nvalue.(Grid.ColumnSpan)" Value="2"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="mobile">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="{StaticResource ScreenWidthZero}"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="cvalue.(Grid.Row)" Value="1"/>
<Setter Target="hvalue.(Grid.Row)" Value="2"/>
<Setter Target="lvalue.(Grid.Row)" Value="3"/>
<Setter Target="nvalue.(Grid.Row)" Value="4"/>
<Setter Target="cvalue.HorizontalAlignment" Value="Right"/>
<Setter Target="hvalue.HorizontalAlignment" Value="Right"/>
<Setter Target="lvalue.HorizontalAlignment" Value="Right"/>
<Setter Target="nvalue.HorizontalAlignment" Value="Right"/>
<Setter Target="cvalue.(Grid.ColumnSpan)" Value="4"/>
<Setter Target="hvalue.(Grid.ColumnSpan)" Value="4"/>
<Setter Target="lvalue.(Grid.ColumnSpan)" Value="4"/>
<Setter Target="nvalue.(Grid.ColumnSpan)" Value="4"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock
Grid.ColumnSpan="4"
Style="{StaticResource FlyoutPickerTitleTextBlockStyle}"
Text="{Binding Symbol, Mode=OneWay, UpdateSourceTrigger=Default}"/>
<TextBlock
Name="cvalue"
Style="{StaticResource CaptionTextBlockStyle}">
<Interactivity:Interaction.Behaviors>
<Core:DataTriggerBehavior Binding="{Binding CurrentValue, Mode=OneWay, UpdateSourceTrigger=Default}">
<Media:ControlStoryboardAction
Storyboard="{StaticResource cValueSB}"
ControlStoryboardOption="Play"/>
</Core:DataTriggerBehavior>
</Interactivity:Interaction.Behaviors>
<Run Text="Current value:"/>
<Run Text="{Binding CurrentValue, Mode=OneWay, UpdateSourceTrigger=Default}"/>
</TextBlock>
<TextBlock
Name="hvalue"
Style="{StaticResource CaptionTextBlockStyle}">
<Run Text="High value:"/>
<Run Text="{Binding HighValue, Mode=OneWay, UpdateSourceTrigger=Default}"/>
<Interactivity:Interaction.Behaviors>
<Core:DataTriggerBehavior Binding="{Binding HighValue, Mode=OneWay, UpdateSourceTrigger=Default}">
<Media:ControlStoryboardAction
Storyboard="{StaticResource hValueSB}"
ControlStoryboardOption="Play"/>
</Core:DataTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</TextBlock>
<TextBlock
Name="lvalue"
Style="{StaticResource CaptionTextBlockStyle}">
<Run Text="Low value:"/>
<Run Text="{Binding LowValue, Mode=OneWay, UpdateSourceTrigger=Default}"/>
<Interactivity:Interaction.Behaviors>
<Core:DataTriggerBehavior Binding="{Binding LowValue, Mode=OneWay, UpdateSourceTrigger=Default}">
<Media:ControlStoryboardAction
Storyboard="{StaticResource lValueSB}"
ControlStoryboardOption="Play"/>
</Core:DataTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</TextBlock>
<TextBlock
Name="nvalue"
Style="{StaticResource CaptionTextBlockStyle}">
<Run Text="Net change:"/>
<Run Text="{Binding NetChangeValue, Mode=OneWay, UpdateSourceTrigger=Default}"/>
<Interactivity:Interaction.Behaviors>
<Core:DataTriggerBehavior Binding="{Binding NetChangeValue, Mode=OneWay, UpdateSourceTrigger=Default}">
<Media:ControlStoryboardAction
Storyboard="{StaticResource lValueSB}"
ControlStoryboardOption="Play"/>
</Core:DataTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</TextBlock>
</Grid>
</UserControl>
Проблема, с которой я сталкиваюсьстолкновение состоит в том, что Анимация не работает, когда значение Связывания изменяется.Я бы хотел, насколько это возможно, избегать любого прямого кода, если это абсолютно необходимо.Это даже правильный способ сделать это?Я новичок в Xaml Behaviors, поэтому хотел бы получить некоторую помощь в его реализации.
если есть более изощренный подход для достижения вышеизложенного, я был бы рад узнать об этом.Спасибо.