开发者

WPF Close UserControl in Frame and access Parent Controls

I have a WPF app with a Window (RootWindow) with a Toolbar and a Frame (ContentFrame). Initially the Toolbar is hidden.

I load a Login UserControl into the Frame and when the user correctly logs in I'd like to close the UserControl and then make the Parent Window toolbar visible.

Seems such a simple thing to do.

However, you cannot close a UserControl from wit开发者_运维技巧hin the UserControl. So how do I break out of the UserControl so I can remove it from the RootWindow (ContentFrame.Source=Nothing) and also make the toolbar Visible.

I can get a handle for the Parent Window with the following code but I cannot access the controls within it

Dim parentWindow As Window = Window.GetWindow(Me) 'Get a handle for parent window

Ideally, I'd like to be able to access Parent Window Controls from within a Child UserControl or at least be able to Trigger an event in the Parent Window from the Child UserControl.


To find the parent in the hirearchy you can use this code:
http://www.hardcodet.net/2009/03/detecting-double-click-events-on-the-wpf-datagrid

Although the problem solved in above article is for DataGrid, the code to find parent is generic enough and should work in your case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜