Passing Parameters between xaml window and usercontrol WPF

后端 未结 3 1122
别跟我提以往
别跟我提以往 2021-02-14 04:02

How to pass Parameters from xaml window to WPF usercontrol constructor? I have tried creating dependency property, but it fails to do it. Should I try xaml extensions or is the

3条回答
  •  离开以前
    2021-02-14 04:41

    If your user control will be used at many places, i recommend har07 answer and use dependency property. But if your control will be used just once or two times and you're lazy enough to create a dependency property, you can always create your control from code. For example create a grid as parent and insert your control as child of your grid

    XAML

    
    

    Code

    MyUserControl userControl = new MyUserControl(param);
    Wrapper.Children.Add(userControl);
    

提交回复
热议问题