Wednesday, 26 November 2008

Sub Classing Window and UserControl

I wanted to add a standard method (InjectModel) into our Windows and UserControls and the obvious technique was to subclass them with something like this:
public partial class PersonEditView : WindowBase
{
...
}

public class WindowBase : Window
{
...
}
The xaml then needs to reference the WindowBase class like this:
<local:WindowBase x:Class="INPC2.PersonEditView"
...
xmlns:local="clr-namespace:INPC2"
>
<local:WindowBase.Resources>
...
</local:WindowBase.Resources>
...
</local:WindowBase>
There is no problem with the forward reference to xmlns:local

No comments: