私はあなたの助けが必要です!以下は、私は私のメインのXAMLビューで持っているものは基本的である:PropertyGrid(DevExpress)のハイブリッドMVVM実装
<Button x:Name="button1" Content= "{Binding Customer1, Mode=TwoWay}" Margin="271,52,103,106" Click="button1_Click" />
メインXAML(コードビハインドのコードビハインド、それは100%純粋なMVVM、むしろハイブリッド1ではありませんので、 )このように書きます:
public MainWindow()
{
InitializeComponent();
this.DataContext = new MyViewModel();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
DXDialog d = new DXDialog("Information", DialogButtons.OkCancel,true);
d.Content = new PropertyGrid();
d.SizeToContent = System.Windows.SizeToContent.WidthAndHeight;
d.Owner = this;
d.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
var result = d.ShowDialog();
if (result == true)
{
}
}
あなたが見ることができるように、私はそのコンテンツのViewModelクラスのStringプロパティにバインドされたボタンがあります。ボタンをクリックすると、ViewModelクラスのPropertiesを持つPropertyGridを含むDXDialogを開きます。私は、プロパティの値を編集することができることだが、まだ私はそれがすぐという方法でそれを保存することができますかわからないダイアログで
public class MyViewModel : ViewModelBase, INotifyPropertyChanged
{
Customer currentCustomer;
protected string _customer1;
public string Customer1 {
get { return this._customer1; }
set { this.SetProperty(ref this._customer1, value, "Customer1"); }
}
public MyViewModel()
{
//Customers = new ObservableCollection<Customer>();
//Customers.Add(new Customer() { Name = "Name1" });
Customer1 = "ABC";
}
}
:私は下にあなたに私ののViewModelクラスをお見せしましょうメインビューのボタンにも反映されています{どこにでも拘束されなければならないことを反映しています}。私は
if (result == true)
{
}
の背後にある主なコードで実行が次の行に来るのを見ることができますしかし、私は編集した値を取得し、適切な場所にそれらを接続する方法がわかりません。
基本的には、複数のコントロール(この場合はボタン)をViewModelクラスの複数のインスタンスにバインドしてから、ボタンをクリックすると、PropertyGrid内の特定のViewModelインスタンスを編集できる必要があります「OK」をクリックすると、関連するボタンにも変更内容が反映されます。
-Ron