Binding UserControl in XAML

2019-09-03 09:58发布

问题:

I am trying to bind a userControl that I create in a class as property. I couldnt figure out how to show it in XAML.

Example:

public class MainWindowViewModel : ViewModelBase
{
    public UserControl myUserControl { get; set; };

    public MainWindowViewModel()
        : base()
    {
        _myUserControl = new WelcomePageView());

    }
}

In XAML:

<Window c:Class=".."
   .
   .
   .
 />
<???? {Binding myUserControl}>
</Window>

回答1:

Try

<ContentControl Content="{Binding your_usercontrol}" />