0
我必須有TimePicker
和驗證規則WPF DelegateCommand和ValidationRules
<controls:TimePicker Grid.Row="0" Grid.Column="1" Culture="Ru-ru" Margin="5,5,5,2.5">
<controls:TimePicker.SelectedTime>
<Binding Path="EditTimeStart" Mode="TwoWay" NotifyOnValidationError="True" >
<Binding.ValidationRules>
......
</Binding.ValidationRules>
</Binding>
</controls:TimePicker.SelectedTime>
</controls:TimePicker>
和一個按鈕( 「保存」)。
<Button Content="Save" Command="{Binding Path=SaveCommand}"/>
在我的視圖模型
SaveCommand = new DelegateCommand(Save, CanSave);
其中CanSave
方法過程的另一сonditions(條件不與ValidationRules相交)
問題。我可以SaveButton啓用綁定到validationriles和CanSave
方法嗎?
由於這個特殊原因,在UI中進行驗證是一個糟糕的主意。更好地實施INotifyDataErrorInfo,它會在UI中顯示錯誤,並且可以從CanSave方法進行查詢。 – Will
爲什麼壞主意?除了我無法調用CanSave方法 – mi4man
這是一個壞主意,因爲您無法訪問在視圖模型中在UI中定義的驗證錯誤。 – Will