【发布时间】:2020-08-17 14:47:36
【问题描述】:
我正在尝试通过代码设置 TextBox 的 VisualState。
<TextBox x:Name="txtbox" Width="438" Height="56" Style="{StaticResource ExtendeTextBoxStyle}"
PlaceholderText="{x:Bind PlaceholderText, Mode=OneWay}" ></TextBox>
代码隐藏
private static void HasErrorUpdated(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
EditTextControl textBox = d as EditTextControl;
Grid sds = textBox.Content as Grid;
var mytxt = sds.Children.FirstOrDefault() as Control;
if (textBox != null)
{
if (textBox.HasError)
VisualStateManager.GoToState(mytxt , "InvalidState", true);
else
VisualStateManager.GoToState(mytxt, "ValidState", false);
}
}
但是这种视觉状态永远不会被激活。这里有什么问题?
【问题讨论】:
-
检查
VisualStateManager.GoToState方法的返回值。是否返回true?
标签: c# xaml uwp visualstatemanager