I am developing WPF application which contains MainWindow.xaml as container to display all user controls inside the Mainwindow .I have defined all the menus inside the Mainwindow.xaml and displaying the respective usercontol inside mainwindow.xaml grid.
Below is my Mainwindow grid definition and respective codebehind event handler code
<Grid x:Name="Container" Grid.Column="0" Width="0" Margin="0,0,0,10" Visibility="Visible">
</Grid>
Code Behind Menu click Event Handler
When the maindow is loaded after login it will call and display the CustomerListView user control
private void Window_Loaded(object sender, RoutedEventArgs e)
{
CustomerListView CLView = new CustomerListView ();
Container.Children.Clear();
Container.Children.Add(CLView );
Container.Children[0].SetValue(WidthProperty, CLView.Width);
Container.Children[0].SetValue(HeightProperty, CLView.Height);
}
//Customer Menu Click Event
public void NewCustomer_Menu_Click(object sender, RoutedEventArgs e)
{
//AddCustomer is User control
AddCustomer AddEmployeeObject = new AddCustomer();
Container.Children.Clear();
Container.Children.Add(AddEmployeeObject);
Container.Children[0].SetValue(WidthProperty, AddEmployeeObject.Width);
Container.Children[0].SetValue(HeightProperty, AddEmployeeObject.Height);
}
Everything works fine until i integrate my application by new login control.After successful login i displayed mainwindow. If i am doing some actions like adding new customers(separate user control) or editing new customers(seperate user control) my application get closed automatically.How to overcome this issue?
Code to display mainwinow after logged in
if (IsValidUser)//Bool variable to validate user
{
//Hide the Loginwindow
this.Hide();
//Display mainwindow
MainWindow objMainWindow = new MainWindow();
objMainWindow.ShowDialog();
}
If i do any update or insert operations it closes the application after insert or update or refresh. It seems every time Maindow is reloads after the insert or update or trying to load another user control or refresh the user control inside the mainwindow grid.How to resolve this?
Woha !!! Got the solution finally. I have defined the button with IsCancel="True" property.So when ever i submit the data it closes the Mainwindow.It's just the copy paste mistake and finally removed the IsCancel attribute and works fine.