I have a MainViewModel class which is the basis for my navigation.
Within that class I have this method with the purpose of changing the parameter object passed in to the selected vendor.
class MainViewModel
{
public Command ShowVendorDialogCommand
{
get;
private set;
}
private void ShowVendorDialog(object parameter)
{
if (parameter != null)
{
VendorDialog vd = new VendorDialog();
VendorDialogViewModel vm = new VendorDialogViewModel();
vd.DataContext = vm;
vm.PropertyChanged += (s, e) =>
{
if (e.PropertyName == "CloseDialog")
{
vd.Close();
}
};
vd.ShowDialog();
if (vm.DialogResult)
{
parameter = vm.SelectedVendor.Copy() as Vendor;
}
}
}
}
The class that is affected by this method is below:
class InventoryStyleSingleViewModel
{
public Vendor
{
get
{
retu _Vendor;
}
set
{
if (value != null)
{
_Vendor = value;
OnPropertyChanged("Vendor");
}
}
}
private Vendor _Vendor;
........
}
I am essentially trying to pass the Vendor property as a reference type through the CommandParameter property to the ShowVendorDialog which is executed through a RelayCommand, I am just not sure how to accomplish the reference part.
Here is the xaml that binds to the ShowVendorDialogCommand.
<Button Width="50" DockPanel.Dock="Left" Command="{Binding ElementName=BeginWindow, Path=DataContext.ShowVendorDialogCommand}" CommandParameter="{Binding Vendor}" Content="..." />
This does not accomplish what I need as the Vendor property is passed by value into the ShowVendorDialog function.
Is there anyway to pass the Vendor by reference?
