当我在另一个项目中继承自定义UserControl时,为什么会出现XamlParseException?

时间:2009-09-29 16:17:17

标签: wpf xaml inheritance user-controls

在一个项目中,我有一个编辑类:

namespace TestXamlInherit234
{
    public class CustomerEditor : BaseEditor
    {
        public CustomerEditor()
        {
            TheMessage.Text = "changed222";
        }
    }
}

继承自另一个项目中的WPF用户控件:

using System.Windows.Controls;

namespace Core
{
    public partial class BaseEditor : UserControl
    {
        public TextBlock TheMessage
        {
            get
            {
                return TheMessage2;
            }
        }

        public BaseEditor()
        {
            InitializeComponent();

        }
    }
}


<UserControl x:Class="Core.BaseEditor"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="300" Width="300">
    <Grid>
        <TextBlock x:Name="TheMessage2" Text="This is in the base editor"/>
    </Grid>
</UserControl>

当两个类都在同一个项目中时 但是当它们在两个不同的项目中时,我得到 XamlParseException 错误。< / p>

1 个答案:

答案 0 :(得分:0)

尝试:

<Core:BaseEditor x:Class="TestXamlInherit234.CustomerEditor"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Core="yourcorenamespace"
    Height="300" Width="300">
    <Grid>
        <TextBlock x:Name="TheMessage2" Text="This is in the base editor"/>
    </Grid>
</Core:BaseEditor>

WPF对继承任何类型的UserControl的支持非常有限。当我这样做以解决缺乏泛型支持时,我必须在代码中定义我的控件并从ContentControl派生。