WPF传递参数以在XAML中查看

时间:2019-06-11 13:07:07

标签: c# wpf xaml

我正在尝试将数据对象传递给XAML中的UserControl。

我尝试过:

<Window x:Class="Wizard.View.CTabView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:views="clr-namespace:Wizard.View">
            <views:ViewOne ViewOneData="{Binding MyData}"/>
</Window>

我的课程:

public partial class ViewOne : UserControl
{
    public CData ViewOneData { get; set; }

    public ViewOne()
    {
        InitializeComponent();
    }
}

public partial class CTabView : Window
{
    public CData MyData { get; set; }

    public CTabView()
    {
        InitializeComponent();
    }
}

我收到此错误:

A first chance exception of type 'System.Windows.Markup.XamlParseException'
occurred in PresentationFramework.dll

Additional information: A 'Binding' cannot be set on the 'Data' property
of type 'CFrameworkGeneralView'.
A 'Binding' can only be set on a DependencyProperty of a DependencyObject.

我的问题有解决方案吗? 还是我应该使对象CData静态(这是我真正不想要的解决方案)?

0 个答案:

没有答案