私はWPFとMVVMを初めて使用するので、我慢してください。
基本的に、ユーザーが組織の詳細をデータベースに入力できるようにするアプリケーションを作成しています。
作成しているWPFアプリケーション内に、、およびメソッドView Model
を含むがあります(これがMVVMを使用する正しい方法ではないことはわかっていますが、それを実現する方法をゆっくりと学んでいます)。properties
commands
entity framework
私のビューの1つでは、これはタブコントロールであり、ユーザーがデータベースにさまざまな組織の詳細を入力できるようにします。次に、別のビューでは、ユーザーが入力した内容を表示するデータグリッドがあり、ユーザーがコンテンツを更新できるようにします。必要です。
それが私の質問につながります。これまでのところ、コマンドを検証して、特定のフィールドが空の場合、ボタンはアクティブになりませんが、入力するとアクティブになるようにしました。そのようです;
private ICommand showAddCommand;
public ICommand ShowAddCommand
{
get
{
if (this.showAddCommand == null)
{
this.showAddCommand = new RelayCommand(this.SaveFormExecute, this.SaveFormCanExecute);//i => this.InsertOrganisation()
}
return this.showAddCommand;
}
}
private bool SaveFormCanExecute()
{
return !string.IsNullOrEmpty(OrganisationName) && !string.IsNullOrEmpty(Address) && !string.IsNullOrEmpty(Country) && !string.IsNullOrEmpty(Postcode)
&& !string.IsNullOrEmpty(PhoneNumber) && !string.IsNullOrEmpty(MobileNumber) && !string.IsNullOrEmpty(PracticeStructure) && !string.IsNullOrEmpty(PracticeType) && !string.IsNullOrEmpty(RegistrationNumber);
}
private void SaveFormExecute()
{
InsertOrganisations();
}
Xaml:
<Button Content="Save" Grid.Column="1" Grid.Row="18" x:Name="btnSave" VerticalAlignment="Bottom" Width="75" Command="{Binding ShowAddCommand}"/>
しかし、私が達成したいと思っていたのは、ユーザーが1つの組織にデータベースに入力すると、コマンドが完全にアクティブになることはなく、ユーザーが誤って別の組織に入るのを防ぐことです。目的は、1つの組織のみを追加できるようにすることであり、それ以上でもそれ以下でもありません。
これは可能ですか?