当我在DependencyProperty中调用它时,VisualStateManager.GoToState不起作用

时间:2010-12-01 03:13:42

标签: silverlight silverlight-4.0

我创建一个DependencyProperty(例如:MyEffect)并将此属性用于我的文本框。

<TextBox Grid.Row="0" x:Name="MyTextBox"                        
                        Text ="{Binding Model.MyValue}"                             
                        behaviors:MyEffect="{Binding EffectSample}">
</TextBox>

在PropertyChangedCallback函数中,我调用

myControl.SetValue(TextBox.TextProperty, "Hello");
VisualStateManager.GoToState(myControl, "InvalidFocused", true);

我的文本框显示“Hello”,但其状态不会更改为InvalidFocused。那么如何更改文本框的状态呢?

1 个答案:

答案 0 :(得分:0)

这不是我的头脑,但它可能是你传递给GotToState方法的类型。它期待一个控件所以我会做以下,假设myControl作为DependencyProperty传入。

var control = myControl as Control;
VisualStateManager.GoToState(myControl, "InvalidFocused", true);

相关问题