I’m working in WPF and I’m facing an issue regarding NDI container
In my MainWindow Xaml I have the MainMdiContainer
<mdi:MdiContainer Theme="Aero" mdi:MdiChild.Closed="MdiChild_Closed" Margin="0,0,0,80" Name="MainMdiContainer" Grid.Row="1" Background="{x:Null}">
</mdi:MdiContainer>
Of course I have another xaml page named “Registration” and I also have a button in mainWindow to open the mdiChild
Public Sub btnAddUser_Click(sender As Object, e As System.Windows.RoutedEventArgs) Handles btnAddUser.Click
MainMdiContainer.Children.Clear()
MainMdiContainer.Children.Add(New MdiChild() With { _
.Title = "Πρόγραμμα Εσωτερικής Διαχείρισης Διορισμός Επιτροπής και Χρηστών", _
.Height = (System.Windows.SystemParameters.PrimaryScreenHeight - 500), _
.Width = (System.Windows.SystemParameters.PrimaryScreenWidth - 430), _
.Style = Nothing, _
.Content = New Registration() _
})
End Sub
Public Sub MdiChild_Closed(sender As System.Object, e As System.Windows.RoutedEventArgs)
For Each child As MdiChild In MainMdiContainer.Children.ToList()
If (child.Name.ToString().Contains("mdiChildRegistration")) Then
MainMdiContainer.Children.Remove(child)
End If
Next
End Sub
Until this stage everything goes fine and the mdiChild opens
Now I want to close the child window by pushing a button
Private Sub btnClose_Click(sender As Object, e As System.Windows.RoutedEventArgs) Handles btnClose.Click
Dim mainWin As New MainWindow
Dim mdiCont As MdiContainer = mainWin.MainMdiContainer
mainWin.MdiChild_Closed(sender, e)
End Sub
But the mdiChild it not close… in fact the Childern in mdiCont is empty. When I add a Childern
<mdi:MdiChild IsTabStop="False" />
In MainWindow then the Childern in mdiCont is not empty it has one Child which is closed when I'm try to open my child whindow by pressing the button. I suspect that something in the add procedure has to do with but I don’t know what. Is there someone to assist me?
Finally I've made it to clese the child window
And all comes from the child code behind
Private Sub btnClose_Click(sender As Object, e As System.Windows.RoutedEventArgs) Handles btnClose.Click
Dim mainWin As MainWindow = Economy.Application.Current.MainWindow
mainWin.MainMdiContainer.Children.Clear()
In the declaration of mainWin it has to be refered as
'Object.Application.Current.MainWindow'
in order to transfer the child window attributes and have the ability to clear it.
Not Removed because the Remove is not clear the child window.
Thank you very much for @dymanoid.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加