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を使用します..反対のバリアントはどうですか...