我正在开发通用应用程序。在一页上,我决定使用FlipView。我可以轻松地从代码背后动画SelectionChanged事件,但我只是好奇是否有一种方法来动画这个事件仅使用XAML。(顺便说一下,UseTouchAnimationsForAllNavigation=的“真”不起作用)。下面是我所做工作的简化例子:
<FlipView x:Name="MultipleItems">
<FlipView.Triggers>
<EventTrigger RoutedEvent="Selector.SelectionChanged">
<BeginStoryboard>
<Storyboard x:Name="ColorStoryboard">
//do stuff
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<FlipView.Triggers>
</FlipView>我认为这种使用EventTrigger的方式很好(就SelectionChanged事件接受从RoutedEventArgs继承的参数而言),但它仍然给我在导航到包含FlipView的页面的运行时错误。
下一个错误是:
WinRT information: Failed to assign to property 'Windows.UI.Xaml.EventTrigger.RoutedEvent'. [Line: 69 Position: 35]
Additional information: The text associated with this error code could not be found.我相信有正确分配RoutedEvent属性的方法,但是我还没有找到它。而且,我也不习惯在这样简单的事情上使用行为。
有人能帮忙吗?
发布于 2016-07-09 08:25:45
您需要在项目中安装Microsoft.Xaml.Behaviors.Uwp.Managed。然后,EventTrigger将在一个UWP项目中得到支持。
然后在XAML中使用这个包,如下所示:
xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
xmlns:Media="using:Microsoft.Xaml.Interactions.Media"例如,现在可以像这样更改FlipView的背景色:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.Resources>
<Storyboard x:Key="std" x:Name="std" >
<ColorAnimation From="Red" To="Transparent" Duration="0:0:3"
Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)"
Storyboard.TargetName="flipView"/>
</Storyboard>
</Grid.Resources>
<FlipView x:Name="flipView" ItemsSource="{x:Bind flipviewCollection}">
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="SelectionChanged">
<Media:ControlStoryboardAction Storyboard="{StaticResource std}" />
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
<FlipView.ItemTemplate>
<DataTemplate>
<Image Source="{Binding ImageSource}" Stretch="None"/>
</DataTemplate>
</FlipView.ItemTemplate>
</FlipView>
</Grid>如您所见,我使用了EventTriggerBehavior,事件名为SelectionChanged。
https://stackoverflow.com/questions/38273003
复制相似问题