I'm struggling in WPF application to initialize object with help of a wizard-like window. I've got main application window which is meant to show the contents of a Plan
object. I want to initialize the Plan
object in another window which is something like a wizard to help user parametrize Plan
.
The concept is following:
MainWindow.xaml.cs
public partial class MainWindow : RibbonWindow
{
public Plan apActivePlan;
public MainWindow()
{
InitializeComponent();
}
private void rbNewPlan_Click(object sender, RoutedEventArgs e)
{
WndAddEditPlan wndAddPlan = new WndAddEditPlan(ref apActivePlan);
wndAddPlan.ShowDialog();
if (wndAddPlan.DialogResult.HasValue && wndAddPlan.DialogResult.Value)
{
/* "Create" button clicked in wndAddPlan,
* so we update the ListView in MainWindow */
lvPlanRows.ItemsSource = this.apActivePlan.Rows; // this is where the problem occurs - apActivePlan is null despite the fact that it has been initialized by wndAddPlan
}
}
WndAddEditPlan.xaml.cs
public partial class WndAddEditPlan : Window
{
Plan apActivePlan = null;
public WndAddEditPlan(ref Plan apActivePlan)
{
InitializeComponent();
this.apActivePlan = apActivePlan;
if(this.apActivePlan == null)
this.apActivePlan = new Plan();
}
private void btnCreatePlan_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
}
}
The user clicks on NewPlan
button and wizard pops up to create new Plan
. The user fills up required information and clicks on CreatePlan
button. The wizard closes but the apActivePlan within MainWindow is not being initialized.