<ItemsControl ItemsSource="{Binding Items}"> .... <ItemsControl.ItemTemplate> <DataTemplate> <GrID ...> <visualstatemanager.VisualStateGroups> <VisualStateGroup x:name="CommonStates"> ... <VisualState x:name="pressed"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="borderThickness" Storyboard.Targetname="GrIDItemborder"> <discreteObjectKeyFrame KeyTime="0" Value="3"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> </visualstatemanager.VisualStateGroups> <border x:name="border" ...> ... </border> </GrID> </DataTemplate> </ItemsControl.ItemTemplate></ItemsControl>解决方法 简短的回答是,您所针对的控件类型没有“按下”的可视状态 – 因此,虽然您可以在Visual State Manager中引用任何状态,但这并不重要,因为控件的代码永远不会放置它进入那个州.
您可以通过查看其定义(使用TemplateVisualState属性声明它们)或查看this section on MSDN来查看控件支持哪些视觉状态.
这里的方法可能是使用button(或你写的[buttonBase] [2]的覆盖),因为它具有内置的“pressed”视觉状态.你只需要编写一个控制模板它提供了你所追求的布局/风格.
编辑这是一个例子:
控制模板(资源部分).这是button控件的控件模板,但它实际上不是一个按钮.我只是用它来利用“pressed”视觉状态功能.
<ControlTemplate x:Key="MybuttonTemplate" targettype="button"> <GrID> <visualstatemanager.VisualStateGroups> <VisualStateGroup x:name="CommonStates"> <VisualState x:name="pressed"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(border.borderThickness)" Storyboard.Targetname="GrIDItemborder"> <discreteObjectKeyFrame KeyTime="0" Value="3"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> </visualstatemanager.VisualStateGroups> <border x:name="GrIDItemborder" borderBrush="Orange" borderThickness="1" Background="White"> <ContentPresenter Content="{TemplateBinding Content}" /> </border> </GrID> </ControlTemplate>
物品控制
将项目模板定义为使用上述ControlTemplate的“button”.
<ItemsControl ItemsSource="{Binding SelectedItems}"> <ItemsControl.ItemTemplate> <DataTemplate> <button Template="{StaticResource MybuttonTemplate}" Content="{Binding}" /> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl>总结
以上是内存溢出为你收集整理的silverlight – 我可以在ItemTemplate中更改DataTemplate的VisualState吗?全部内容,希望文章能够帮你解决silverlight – 我可以在ItemTemplate中更改DataTemplate的VisualState吗?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)