【问题标题】:Binding UserControl in XAML在 XAML 中绑定用户控件
【发布时间】:2011-03-14 13:13:22
【问题描述】:

我正在尝试将我在类中创建的 userControl 绑定为属性。我不知道如何在 XAML 中显示它。

例子:

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

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

    }
}

在 XAML 中:

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

【问题讨论】:

    标签: wpf binding user-controls


    【解决方案1】:

    试试

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

    【讨论】:

    • 这不起作用,myViewUserControl 不可见。尝试添加的 UserControl 具有 ViewPort3d 元素,是否需要任何东西才能看到..
    • 好吧,真丢脸!我只是注意到宽度和高度值是自动的。所以他们的能见度消失了。那行得通.. :)
    猜你喜欢
    • 1970-01-01
    • 2016-01-12
    • 2012-04-15
    • 1970-01-01
    • 2012-02-27
    • 2011-04-12
    • 2010-11-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多