在xaml中创建自定义VisualState并在CodeBehind中手动设置它 [英] Create custom VisualState in xaml and manually set it in CodeBehind

查看:104
本文介绍了在xaml中创建自定义VisualState并在CodeBehind中手动设置它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a TabItem style, which has VisualStates.

<VisualState x:Name="MouseOver"> 
<!-- Tab turns bronze when mouseover -->
</VisualState>



现在我想有一个自定义可视化状态,并手动设置codebehind的状态,而不是依赖MouseOver事件。

Now I want to have a custom visual state and manually set the state in codebehind instead of relying on the MouseOver event.

<VisualState x:Name="CustomVisualState">
<!-- this will be a storyboard to cause flashing -->
</VisualState> 

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

Then I need to set it in CodeBehind.

MyTabItem.VisualState = CustomVisualState.  //something like this


推荐答案

=http://msdn.microsoft.com/en-us/library/dd991369(v=vs.110).aspx =nofollow> VisualStateManager.GoToState(Control,stateName,UseTransition); < a> Takes a Control,带有自定义状态名称的字符串和使用转换的bool标志。

此处的添加示例

Have you tried VisualStateManager.GoToState(Control,"stateName",UseTransition); Takes a Control, string with the custom state name and a bool flag for using transitions.
Addtional Example here

这篇关于在xaml中创建自定义VisualState并在CodeBehind中手动设置它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆