I am very new to WPF. I am trying to create Add/Edit form. I have also added Caliburn.Micro frameowrk for MVVM.
I have created one screen for Add
or Edit
. I do not know how to pass model Id
to my ViewModel
. How?
Currently my View (Window)
works only for Add
and not Edit
.
- AddOrderViewModel.cs
- corresponding AddOrderView.xaml
The classes are like this:
public class OrderAddEditViewModel : Screen {
public OrderAddEditViewModel( ) {};
// I do not know if this is normal approach or not
public OrderAddEditViewModel(int orderId) { // Load Order from DB};
...
}
public partial class OrderAddEditView : Window ...
Now, when pressing button on Main form
, I am opening OrderAddEditView
//This loads empty form for Add
// What if I have OrderId and want to load it, HOW?
var frm = new OrderAddEditView();
frm.Show();
There is some magic behind, and OrderAddEditView
knows which view model to use (this is WPF + Caliburn.Micro
).
However, currently I want to pass "OrderId
" to my OrderAddEditViewModel
's constructor (this will load data from DB) and open OrderAddEditView
so that constructor with id would be invoked.