0

MVVM、Devexpress WPF、c# の使用

たとえば、ビューに2つのアイテムがあり(実際のプロジェクトにはもっとあります)、それらを使用してユーザーがいくつかの検索パラメーターを入力し、それらを検証すると同時に別のアイテムを無効にする必要があります。 .

入力したテキストの長さが必要な長さを満たしていない場合でも、有効/無効にする必要があります。

Xaml を表示:

<dxe:TextEdit

  Text="{Binding SearchField1, UpdateSourceTrigger=PropertyChanged}"
  Validate="searchFieldValidate"/>

<dxe:TextEdit
      IsEnabled="{Binding IsTextItemEnabled}"
      Text="{Binding SearchField2, UpdateSourceTrigger=PropertyChanged}"
      Validate="searchFieldValidate"/>

c#

private void searchFieldValidate(object sender, DevExpress.Xpf.Editors.ValidationEventArgs e)
        {
            if (e.Value == null) return;
            if (e.Value.ToString().Length > 5) return;
            e.IsValid = false;
            e.ErrorType = DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning;
            e.ErrorContent = "Enter more than 5 symbol";
        }

ViewModel ここで IsTextItemEnabled を値が空か mot かに応じて設定します

public string SearchField1
        {
            get { return _searchField1; }
            set
            {
                if (value != _searchField1)
                {
                    _searchField1 = value;

                    if (!String.IsNullOrEmpty(value))
                        IsTextItemEnabled = false;
                    else
                        IsTextItemEnabled = true;

                    RaisePropertiesChanged("SearchField1");
                }
            }
        }

問題は、フィールドの長さが 5 シンボルに達するまで RaisePropertiesChanged が機能しないことです。

この問題を解決するのを手伝ってくれませんか? まず、1つのフィールドを無効にしようとしているので、1つのbool IsTextEnabledを使用します..反対のバリアントはどうですか...

4

1 に答える 1

0

TextEdit に名前を付けました

<dxe:TextEdit
 Name="txtEdit1"
 Text="{Binding SearchField1, UpdateSourceTrigger=PropertyChanged}"
 Validate="searchFieldValidate"/>

<dxe:TextEdit
 Name="txtEdit2"
 Text="{Binding SearchField2, UpdateSourceTrigger=PropertyChanged}" />

手順を検証する行を追加します。

txtEdit2.IsEnabled = String.IsNullOrEmpty(e.Value?.ToString());

これで、一度に検証と有効化/無効化を行うことができます..今回は OnPropertiesChanged を使用しないでください

于 2016-12-12T10:14:17.453 に答える