如果密码不正确,我正在尝试设置 a 的视觉状态PasswordBox
以指示错误。
根据 MSDN 文档PasswordBox Syles and Templates(他们的拼写错误),在以下视觉状态组中定义了以下视觉状态:
- 正常 - CommonStates
- 鼠标悬停 - CommonStates
- 已禁用 - CommonStates
- 专注 - FocusStates
- 不专心 - FocusStates
- 有效 - ValidationStates
- InvalidFocused - ValidationStates
- InvalidUnfocused - ValidationStates
但是,以下代码总是返回一个空列表:
public void Blah(PasswordBox passwordBox)
{
var visualStateGroups = VisualStateManager.GetVisualStateGroups(passwordBox);
//visualStates.Count is always 0.
}
并且试图进入一个状态总是返回错误,例如
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 不正确?