views:

99

answers:

1

In one project I have an Editor Class:

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

which inherits from a WPF User Control in another project:

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>

This works when both classes are in the same project but when they are in two different projects, I get a XamlParseException error.

A: 

Try:

<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's support for inheriting any kind of UserControls is very limited. When I did this to work around the lack of generics support I had to define my control in code and derive from ContentControl.

vanja.
I couldn't get that suggestion to work, and I don't see why in my BaseEditor XAML I would define the CustomerEditor class. For the time being we are also simply doing XAML-less classes across project boundaries but there must be a way to get this to work.
Edward Tanguay