在我的 CustomControl 中,我使用这样的 VisualStateManager:
...
<ControlTemplate TargetType="{x:Type local:MyCustomControl}">
<Grid x:Name="rootGrid" >
<Grid.RowDefinitions>
<RowDefinition Height="65"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CheckStates">
<VisualState x:Name="Checked">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="toggleRegionContent"
Storyboard.TargetProperty="Height"
From="0"
To="{TemplateBinding ContentHeight}"
Duration="0:0:.7" />
<DoubleAnimation Storyboard.TargetName="arrowIcon"
Storyboard.TargetProperty="(Path.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)"
From="0"
To="180"
Duration="0:0:.1" />
</Storyboard>
<VisualState>
<!-- Some other States -->
</VisualStateGroup>
</VisualStateManager>
<ToggleButton>
<!-- The Rest of the Control -->
我现在的问题是如何处理已检查的事件或由谁处理它。单击 ToggleButton 时 VisualStateManager 是否自动切换状态。或者我是否必须给我的 ToggleButton 一个选中事件,并在代码隐藏中分配按钮的状态,如下所示:
VisualStateManager.GoToElementState(Control, "Checked", true);
感谢您的帮助。
最佳答案
Or do i have to give my ToggleButton a Checked Event and assign the State of the Button in the Code Behind with something like this:
是的,您的自定义控件负责使用 VisualStateManager
类及其 GoToState
方法设置控件的当前视觉状态。
您可以在 MSDN 上阅读有关此内容的更多信息:https://msdn.microsoft.com/en-us/library/ee330302(v=vs.110).aspx
关于c# - WPF/XAML VisualStateManager 谁处理事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42440605/