Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

closing wpf window from within frame

I'm porting a Winform project to WPF and started working with Windows & Pages (using the frame control). Basically my intention is to navigate from one page to the next until the user logs in successfully. Now since the logIn is handled at the Page level... my question is:

How can the Page Shut Down the Parent Window?!?

Thanks in advance if you know the code in vb. If not I'll figure it out in C#.

Public Sub CloseLogIn()
    Dim LogIn = TryCast(Me.Parent, Window)
    If LogIn IsNot Nothing Then
        LogIn.Close()
    End If
End Sub
like image 804
CogentP Avatar asked Oct 22 '22 14:10

CogentP


1 Answers

Try

Public Sub CloseLogIn()
    Dim LogIn = Window.GetWindow(Me)
    If LogIn IsNot Nothing Then
        LogIn.Close()
    End If
End Sub

The Window.GetWindow() method returns a reference to the Window object that hosts the content tree within which the dependency object is located.

like image 70
BgRva Avatar answered Oct 25 '22 18:10

BgRva