My Child window not closed in WPF

Lefteris Gkinis

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?

Lefteris Gkinis

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]

編集
0

コメントを追加

0

関連記事

分類Dev

Why does my window reopen when closed?

分類Dev

Refresh a WPF page from a child window

分類Dev

How to open a child Window like a splash screen before MainWindow in WPF?

分類Dev

How to instance a child Window in WPF that takes parameters from the main Window, but respects MVVM

分類Dev

How to stretch my (unknown number of) labels when the window is enlarged in wpf?

分類Dev

WPF window maximize

分類Dev

Bring a window to the front in WPF

分類Dev

Page vs Window in WPF?

分類Dev

Bring a window to the front in WPF

分類Dev

Child Window Z-Order

分類Dev

WPF MVVM parent child relationships

分類Dev

IPC::Run - Detection of premature child exit and closed pipes

分類Dev

Parent View doesn't refresh after child view is closed

分類Dev

Prevent stream socket opened in parent to be closed by child fork

分類Dev

Main window does not receive events after modal dialog is closed

分類Dev

WebSocket - can custom onclose function be run when window is closed?

分類Dev

Is it possible to animate after a window you opened using JavaScript is closed?

分類Dev

LINQ TO SQL in WPF Application generating connection is closed exception, sometimes

分類Dev

How to pass data from parent window to child popup window

分類Dev

Passing image selection from child window to MainPage

分類Dev

Is it possible to bind to events on a child window from a parent?

分類Dev

How to have a scrollbar in my div not in my window?

分類Dev

Returning Value From Window To Class WPF

分類Dev

Determining when a WPF window is being moved

分類Dev

automatic open new window without timer WPF

分類Dev

C# WPF Visibility of a TextBox in window constructor?

分類Dev

Splash window doesn't close - WPF

分類Dev

Why is loading my SDF causing Mobilizer creating a closed loop error

分類Dev

My tkinter program to modify a label when a button is pressed is malfunctioning (closed)

Related 関連記事

  1. 1

    Why does my window reopen when closed?

  2. 2

    Refresh a WPF page from a child window

  3. 3

    How to open a child Window like a splash screen before MainWindow in WPF?

  4. 4

    How to instance a child Window in WPF that takes parameters from the main Window, but respects MVVM

  5. 5

    How to stretch my (unknown number of) labels when the window is enlarged in wpf?

  6. 6

    WPF window maximize

  7. 7

    Bring a window to the front in WPF

  8. 8

    Page vs Window in WPF?

  9. 9

    Bring a window to the front in WPF

  10. 10

    Child Window Z-Order

  11. 11

    WPF MVVM parent child relationships

  12. 12

    IPC::Run - Detection of premature child exit and closed pipes

  13. 13

    Parent View doesn't refresh after child view is closed

  14. 14

    Prevent stream socket opened in parent to be closed by child fork

  15. 15

    Main window does not receive events after modal dialog is closed

  16. 16

    WebSocket - can custom onclose function be run when window is closed?

  17. 17

    Is it possible to animate after a window you opened using JavaScript is closed?

  18. 18

    LINQ TO SQL in WPF Application generating connection is closed exception, sometimes

  19. 19

    How to pass data from parent window to child popup window

  20. 20

    Passing image selection from child window to MainPage

  21. 21

    Is it possible to bind to events on a child window from a parent?

  22. 22

    How to have a scrollbar in my div not in my window?

  23. 23

    Returning Value From Window To Class WPF

  24. 24

    Determining when a WPF window is being moved

  25. 25

    automatic open new window without timer WPF

  26. 26

    C# WPF Visibility of a TextBox in window constructor?

  27. 27

    Splash window doesn't close - WPF

  28. 28

    Why is loading my SDF causing Mobilizer creating a closed loop error

  29. 29

    My tkinter program to modify a label when a button is pressed is malfunctioning (closed)

ホットタグ

アーカイブ