2009-09-29 47 views
0

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

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错误。

回答

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对继承任何用户控件的支持是非常有限的。当我这样做是为了解决缺乏泛型支持的问题时,我必须在代码中定义我的控件并从ContentControl派生。

+0

我无法得到该建议的工作,我不明白为什么在我的BaseEditor XAML中我将定义CustomerEditor类。目前,我们也只是在整个项目边界上做XAML-less的类,但是必须有一种方法来实现这个功能。 – 2009-09-30 15:20:25

相关问题