Hello friends
I used mdi in the main window. I have several user control(which include several buttons).
User controls open in mdi.
Now I want to close the user control by clicking the button.
<Window x:Class="Application2.MainWindow"
xmlns:mdi="clr-namespace:WPF.MDI;assembly=WPF.MDI"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Width="1300" Height="700" Loaded="Window_Loaded" >
<Grid >
<DockPanel Height="19" VerticalAlignment="Top">
<Menu Margin="0,0,0,-10" >
<MenuItem Header="File">
<MenuItem Header="New" Name="neww" Click="neww_Click" >
</MenuItem>
</Menu>
</DockPanel>
<Grid Margin="0,63,0,0">
<mdi:MdiContainer Name="container1" Margin="0,8,0,0">
</mdi:MdiContainer>
</Grid>
</Grid>
</Window>
code behind main Window:
private void neww_Click(object sender, RoutedEventArgs e)
{
container1.Children.Add(new MdiChild()
{
Title = "",
Height=247,
Width=444,
Content = new UListNew()
});
}
Inside the user control(UListNew) a button(btnClose) to close.
code behind UListNew:
private void btnClose_Click(object sender, RoutedEventArgs e)
{
MainWindow parentWindow = Window.GetWindow(this) as MainWindow;
parentWindow.container1.Children.RemoveAt( index);
}
now If I have multiple user Control Open ,
How do I get the index user Control for close?
please help to me.
What I have tried:
private void btnClose_Click(object sender, RoutedEventArgs e)
{
MainWindow parentWindow = Window.GetWindow(this) as MainWindow;
parentWindow.container1.Children.RemoveAt( index????);
}