WPF User Control Parent

后端 未结 17 1072
不知归路
不知归路 2020-11-28 02:18

I have a user control that I load into a MainWindow at runtime. I cannot get a handle on the containing window from the UserControl.

I hav

17条回答
  •  清酒与你
    2020-11-28 02:55

    Different approaches and different strategies. In my case I could not find the window of my dialog either through using VisualTreeHelper or extension methods from Telerik to find parent of given type. Instead, I found my my dialog view which accepts custom injection of contents using Application.Current.Windows.

    public Window GetCurrentWindowOfType(){
     return Application.Current.Windows.OfType().FirstOrDefault() as Window;
    }
    

提交回复
热议问题