如何更改数据模板列表框选定项中的路径属性
本文关键字:属性 路径 数据 何更改 列表 | 更新日期: 2023-09-27 18:32:30
我使用列表框来显示图像数据。 我想在列表框上对数据模板内的数据属性进行动画处理,当它被选中时,它就像在这个视频中一样
https://vine.co/v/On03bWIEPJ6
我看到许多与此类似的问题,内容演示者的操纵可以完成这项工作。 但是对于我的问题是我必须更改内容演示器内部的数据模板中的路径属性
尝试#1在我的项模板上创建视觉状态
<DataTemplate x:Key="ItemTemplate">
<Grid Height="456" Width="456" Margin="0,12">
<VisualStateManager.CustomVisualStateManager>
<ec:ExtendedVisualStateManager/>
</VisualStateManager.CustomVisualStateManager>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="VisualStateGroup">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="selected1">
<Storyboard>
<-- this is where code generate from blend goes -->
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Rectangle x:Name="rectangle" HorizontalAlignment="Left" Height="456" Stroke="Black" VerticalAlignment="Top" Width="456">
<Rectangle.Fill>
<ImageBrush ImageSource="{Binding photo}" Stretch="UniformToFill"/>
</Rectangle.Fill>
</Rectangle>
<Path x:Name="rectangle_Copy" Fill="White" HorizontalAlignment="Left" Height="483.793" Stroke="Black" UseLayoutRounding="False" VerticalAlignment="Top" Width="479.386" Margin="-13.052,-13.52,-10.334,-14.273" >
<Path.Data>
<PathGeometry FillRule="EvenOdd">
<PathFigure IsFilled="True" IsClosed="True" StartPoint="13.5517,14.0196">
<LineSegment Point="468.552,14.0196"/>
<LineSegment Point="468.552,469.02"/>
<LineSegment Point="11.427,471.145"/>
</PathFigure>
<PathFigure IsFilled="True" IsClosed="True" StartPoint="468.552,14.145">
<BezierSegment Point3="469.052,469.27" Point2="469.052,469.27" Point1="468.552,14.145"/>
<BezierSegment Point3="11.5517,471.52" Point2="11.5517,471.52" Point1="469.052,469.27"/>
<BezierSegment Point3="13.552,14.02" Point2="13.552,14.02" Point1="11.5517,471.52"/>
<BezierSegment Point3="468.552,14.145" Point2="468.552,14.145" Point1="13.552,14.02"/>
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>
</Grid>
</DataTemplate>
但是我找不到触发此视觉状态的方法 shen 列表框项被选中。
尝试#2我创建了 2 个项目模板,一个用于正常状态,两个用于像这样的选定状态。
<Style x:Key="ListBoxItemStyle1" TargetType="ListBoxItem">
....
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected"/>
<VisualState x:Name="Selected">
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="myListBox" Storyboard.TargetProperty="ItemTemplate">
<DiscreteDoubleKeyFrame KeyTime="0" Value="{StaticResource selectedDataTemplate}"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
当我选择列表框时,这会产生错误,我认为这种方法无法执行动画。
这是我的列表框
<ListBox Name="myListBox" ItemsSource="{Binding Feed}"
SelectionChanged="ListBox_SelectionChanged"
ItemTemplate="{StaticResource ItemTemplate}"
ItemContainerStyle="{StaticResource ListBoxItemStyle1}"/>
请任何帮助会很棒,谢谢之前。
请参阅 http://msdn.microsoft.com/en-us/library/ms742536%28v=vs.110%29.aspx
<ListBox ...>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Trigger.EnterActions>
<!-- What happens when it is selected. Put a StoryBoard here -->
</Trigger.EnterActions>
<Trigger.ExitActions>
<!-- What happens when it is unselected. Put a StoryBoard here -->
</Trigger.ExitActions>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>