我有WinRT电话应用程序,我想使用MVVM命令显示/隐藏顶部导航,但是我遇到了问题。我无法使用VisualState和Animation来使用动画。
编辑:
我在我的堆叠面板上错过了一个rendertransform,但它仍然没有工作。
当我点击调用经典动画的按钮时,stackpanel会隐藏自己。但是我还是无法使用GoToStateAction让堆栈面移动任何想法?
这是我的XAML(已更新):
UIBarButtonItem *searchButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSearch
target:self
action:@selector(searchItem:)];
UIBarButtonItem *editButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemEdit
target:self action:@selector(editItem:)];
self.navigationItem.rightBarButtonItems =
[NSArray arrayWithObjects:editButton, searchButton, nil];
网页代码:
<Page
x:Class="App3.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:App3="using:App3"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Resources>
<Storyboard x:Name="HideTopNavStoryboardV2">
<DoubleAnimation Duration="0:0:0.3" To="-140" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="NavStackPanel" d:IsOptimized="True"/>
<DoubleAnimation Duration="0:0:0.3" To="0" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="NavStackPanel" d:IsOptimized="True"/>
</Storyboard>
</Page.Resources>
<Grid x:Name="LayoutRoot">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="NavigationStateGroup">
<VisualState x:Name="HideTopNavStoryboard">
<Storyboard>
<DoubleAnimation Duration="0:0:0.3" To="-140" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="NavStackPanel" d:IsOptimized="True"/>
<DoubleAnimation Duration="0:0:0.3" To="0" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="NavStackPanel" d:IsOptimized="True"/>
</Storyboard>
</VisualState>
<VisualState x:Name="ShowTopNavStoryboard">
<Storyboard>
<DoubleAnimation Duration="0:0:0.6" To="0" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="NavStackPanel" d:IsOptimized="True"/>
<DoubleAnimation Duration="0:0:0.6" To="0" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="NavStackPanel" d:IsOptimized="True"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<interactivity:Interaction.Behaviors>
<core:DataTriggerBehavior Binding="{Binding DisplayState}" Value="0">
<core:GoToStateAction StateName="ShowTopNavStoryboard" TargetObject="{Binding ElementName=LayoutRoot}"/>
</core:DataTriggerBehavior>
<core:DataTriggerBehavior Binding="{Binding DisplayState}" Value="1">
<core:GoToStateAction StateName="HideTopNavStoryboard" TargetObject="{Binding ElementName=LayoutRoot}"/>
</core:DataTriggerBehavior>
</interactivity:Interaction.Behaviors>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel
x:Name="NavStackPanel"
Grid.Row="0" >
<StackPanel.RenderTransform>
<CompositeTransform/>
</StackPanel.RenderTransform>
<TextBox Text="Search for something" />
<TextBlock Text="{Binding DisplayState ,Mode=TwoWay}" Foreground="Red" FontSize="23" HorizontalAlignment="Center"></TextBlock>
</StackPanel>
</Grid>
<Page.BottomAppBar>
<CommandBar Opacity="0.7">
<AppBarButton Label="Hide" Icon="Up" Command="{Binding CloseCommand}" />
<AppBarButton Label="Show" Icon="Add" Command="{Binding ShowTopNavCommand}" />
<AppBarButton Label="Hide" Icon="UpLoad" Click="ButtonBase_OnClick" />
</CommandBar>
</Page.BottomAppBar>
</Page>
MVVM C#:
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
HideTopNavStoryboardV2.Begin();
}
有谁知道我做错了什么?谢谢你的帮助!