在xaml中创建自定义VisualState并在CodeBehind中手动设置它

ast*_*ght 6 wpf xaml coding-style

我有一个TabItem样式,它有VisualStates.

<VisualState x:Name="MouseOver"> 
<!-- Tab turns bronze when mouseover -->
</VisualState>
Run Code Online (Sandbox Code Playgroud)

现在我希望有一个自定义的可视状态,并在代码隐藏中手动设置状态,而不是依赖于MouseOver事件.

<VisualState x:Name="CustomVisualState">
<!-- this will be a storyboard to cause flashing -->
</VisualState> 
Run Code Online (Sandbox Code Playgroud)

然后我需要在CodeBehind中设置它.

MyTabItem.VisualState = CustomVisualState.  //something like this
Run Code Online (Sandbox Code Playgroud)

Ter*_*nce 14

您是否尝试过VisualStateManager.GoToState(Control,"stateName",UseTransition); 使用自定义状态名称的控件,字符串和使用转换的布尔标志.
这里的附加示例