开发者

Subclassing WPF Window

I created a WPF Window

than i modified its class definition to:

public partial class myWindow : mySubclassedWindow

compiler throws:

"Partial declarations of 'myWindow' must not specify different base classes"

myWindow.Xaml:

x:Class="WpfGridtest.myWindow"

so somewhere, there is another partial class, that inherits from "Window" but i cannot find it. How can i override my case to use subclassed window?


thanks Jon, that was the problem开发者_C百科. also found this helpful article: http://geekswithblogs.net/lbugnion/archive/2007/03/02/107747.aspx


That would be in the declaration of myWindow itself - the designer will be generating the other half of the partial type based on the XAML, based on your element type.

You can use an element of <mySubclassedWindow> instead, so long as you give it the appropriate namespace and assembly references.

EDIT: Okay, so here's a short example, in a project called WpfApplication. My Window subclass:

using System.Windows;

namespace WpfApplication
{
    public class EnhancedWindow : Window
    {
    }
}

My XAML:

<y:EnhancedWindow x:Class="WpfApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:y="clr-namespace:WpfApplication"
        Title="MainWindow" Height="350" Width="525">
</y:EnhancedWindow>

My partial type:

namespace WpfApplication
{
    public partial class MainWindow : EnhancedWindow
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }
}

It all builds with no problem. I think that's what you wanted to do, right?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜