0
にTextBox
という2つの問題があります。この要素のフォーカスを残すにはLostFocusセッター呼び出しがバインドされていません
<TextBox Text="{Binding Path=MyText, Mode="TwoWay", UpdateSourceTrigger=LostFocus}" />
私はText
プロパティが変更されていない場合でも、MyText
のセッターコールを持っていると思います。
public string MyText {
get { return _myText; }
set {
if (value == _myText) {
RefreshOnValueNotChanged();
return;
}
_myText = value;
NotifyOfPropertyChange(() => MyText);
}
}
テスト機能RefreshOnValueNotChanged()
は決して呼び出されません。誰かがトリックを知っていますか? Enter
の動作が添付されているため、UpdateSourceTrigger=LostFocus
が必要です(ユーザー入力が完了する必要があります)。クラスと
<TextBox Text="{Binding Path=MyText, Mode="TwoWay", UpdateSourceTrigger=LostFocus}" >
<i:Interaction.Behaviors>
<services2:TextBoxEnterBehaviour />
</i:Interaction.Behaviors>
</TextBox>
:
public class TextBoxEnterBehaviour : Behavior<TextBox>
{
#region Private Methods
protected override void OnAttached()
{
if (AssociatedObject != null) {
base.OnAttached();
AssociatedObject.PreviewKeyUp += AssociatedObject_PKeyUp;
}
}
protected override void OnDetaching()
{
if (AssociatedObject != null) {
AssociatedObject.PreviewKeyUp -= AssociatedObject_PKeyUp;
base.OnDetaching();
}
}
private void AssociatedObject_PKeyUp(object sender, KeyEventArgs e)
{
if (!(sender is TextBox) || e.Key != Key.Return) return;
e.Handled = true;
((TextBox) sender).MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
}
#endregion
}