【发布时间】:2023-03-25 17:32:01
【问题描述】:
我正在尝试设置PasswordBox 的可视状态,以在密码不正确时指示错误。
根据 MSDN 文档 PasswordBox Syles and Templates(他们的拼写错误),在以下视觉状态组中定义了以下视觉状态:
- 正常 - CommonStates
- MouseOver - CommonStates
- 已禁用 - CommonStates
- 专注 - FocusStates
- 不专注 - FocusStates
- 有效 - ValidationStates
- InvalidFocused - ValidationStates
- InvalidUnfocused - ValidationStates
然而,下面的代码总是返回一个空列表:
public void Blah(PasswordBox passwordBox)
{
var visualStateGroups = VisualStateManager.GetVisualStateGroups(passwordBox);
//visualStates.Count is always 0.
}
并且试图进入一个状态总是返回 false,例如
public void Halb(PasswordBox passwordBox)
{
bool didTransition = VisualStateManager.GoToState(passwordBox,
"InvalidFocused",
true);
//didTransition is always false. It doesn't make a difference whether
//or not the last paramter is "true" or "false"
}
为什么在 msdn 上记录的 VisualStates/VisualStateGroups 显然在代码中丢失了?我做错了什么(我的怀疑),还是 MSDN 不正确?
【问题讨论】: