我有一个包含多个标签的项目。当用户选择一个选项卡时,我希望该选项卡内的网格滑出。我想我可以通过改变网格边距来实现这一点。我实际上有一个有效的解决方案,但它需要包含来自Blend的2个DLL。我认为在不使用Blend的情况下可以实现相同的效果,但我无法弄明白。下面是故事板和tabItems xaml
<Storyboard x:Key="tabAdminSlide">
<ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="grid1">
<EasingThicknessKeyFrame KeyTime="0" Value="400,0,0,0"/>
<EasingThicknessKeyFrame KeyTime="0:0:0.5" Value="0,0,0,0">
<EasingThicknessKeyFrame.EasingFunction>
<ExponentialEase EasingMode="EaseOut"/>
</EasingThicknessKeyFrame.EasingFunction>
</EasingThicknessKeyFrame>
</ThicknessAnimationUsingKeyFrames>
</Storyboard>
<TabItem Header="Run as Admin" x:Name="tabAdmin" Background="LightBlue">
<i:Interaction.Triggers>
<ei:DataTrigger Binding="{Binding SelectedIndex, ElementName=tabControl}" Value="0">
<ei:ControlStoryboardAction Storyboard="{StaticResource tabAdminSlide}"/>
</ei:DataTrigger>
</i:Interaction.Triggers>
<Grid Height="Auto" x:Name="grid1" Width="Auto">
<Grid.Background>
<LinearGradientBrush StartPoint="-0.002,0.498" EndPoint="1.084,0.498">
<GradientStop Color="LightBlue" Offset="0.446" />
<GradientStop Color="White" Offset="1" />
</LinearGradientBrush>
</Grid.Background>
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="40,179,0,0" Name="button1" VerticalAlignment="Top" Width="75" Grid.ColumnSpan="2" />
</Grid>
</TabItem>
看起来像是
<i:Interaction.Triggers>
<ei:DataTrigger Binding="{Binding SelectedIndex, ElementName=tabControl}" Value="0">
<ei:ControlStoryboardAction Storyboard="{StaticResource tabAdminSlide}"/>
</ei:DataTrigger>
</i:Interaction.Triggers>
我需要更换的部件,但我不能确定。任何帮助都是适当的
感谢。
答案 0 :(得分:1)
你应该可以使用
<TabItem.Triggers>
<EventTrigger RoutedEvent="Selector.Selected">
<BeginStoryboard Storyboard="{StaticResource tabAdminSlide}" />
</EventTrigger>
</TabItem.Triggers>
而不是
<i:Interaction.Triggers>
<ei:DataTrigger Binding="{Binding SelectedIndex, ElementName=tabControl}" Value="0">
<ei:ControlStoryboardAction Storyboard="{StaticResource tabAdminSlide}"/>
</ei:DataTrigger>
</i:Interaction.Triggers>