您可以將樣式應用於切換按鈕的動畫不透明度屬性。請參考下面的示例標記,應該給你的想法:
<ListBox.ItemTemplate>
<DataTemplate>
<DataTemplate.Resources>
<Style x:Key="style" TargetType="ToggleButton">
<Setter Property="Opacity" Value="0" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity"
From="0" To="1" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity"
From="1" To="0" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</DataTemplate.Resources>
<Grid HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition x:Name="AnimeatedGrid" Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal">
<ToggleButton />
<ToggleButton />
<TextBlock VerticalAlignment="Center" Text="{Binding Name}" />
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<ToggleButton Content="A" Style="{StaticResource style}" />
<ToggleButton Content="B" Style="{StaticResource style}" />
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
或者,您也可以應用的RenderTransform是的ToggleButtons是動畫和動畫TranslateTransform的X屬性來獲取更多的「滑動」的經驗:
<ListBox.ItemTemplate>
<DataTemplate>
<DataTemplate.Resources>
<Style x:Key="style" TargetType="ToggleButton">
<Style.Triggers>
<DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)" From="-50" To="0" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)" From="0" To="-50" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</DataTemplate.Resources>
<Grid HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition x:Name="AnimeatedGrid" Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal">
<ToggleButton />
<ToggleButton />
<TextBlock VerticalAlignment="Center" Text="{Binding Name}" />
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<ToggleButton Content="A" Style="{StaticResource style}">
<ToggleButton.RenderTransform>
<TranslateTransform X="-50"/>
</ToggleButton.RenderTransform>
</ToggleButton>
<ToggleButton Content="B" Style="{StaticResource style}">
<ToggleButton.RenderTransform>
<TranslateTransform X="-50"/>
</ToggleButton.RenderTransform>
</ToggleButton>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
來源
2016-12-05 22:53:31
mm8
完美。像魅力一樣工作......謝謝! – RBasniak