Click here to Skip to main content
15,899,474 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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.
HTML
<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:
C#
private void neww_Click(object sender, RoutedEventArgs e)
      {

       container1.Children.Add(new MdiChild()
          {
              Title = "",
            Height=247,
            Width=444,

              Content = new UListNew()// it is user control
          });
      }

Inside the user control(UListNew) a button(btnClose) to close.
code behind UListNew:
C#
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:

C#
private void btnClose_Click(object sender, RoutedEventArgs e)
       {
           MainWindow parentWindow = Window.GetWindow(this) as MainWindow;
           parentWindow.container1.Children.RemoveAt( index????);
       }
Posted
Comments
phil.o 19-Oct-17 7:21am    
We may have no idea where the WPF.MDI assembly comes from, nor how to use its functionalities. It is not part of standard framework. Therefore, you may have a hard time finding a relevant and useful answer.
Dave Kreskowiak 19-Oct-17 8:57am    
Standard WPF doesn't have an MDI container. This is a 3rd party control you're talking about. Where did you get it from and why are you not asking those people for support on it?
mahdiiiiyeh 19-Oct-17 10:50am    
Many Application are made with MDI container.Using WPF.mdi.dll.
I want to get current Index user control.
parentWindow.container1.Children.RemoveAt( index????);
or
how to get current mdi child instance?
parentWindow.container1.Children.Remove( ?????);
please guide me
Dave Kreskowiak 19-Oct-17 11:22am    
First, MDI is a dead concept. Again, WPF has no inbuilt support for MDI. This is a third party control you're using. Where did you get it from?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900