Deriving A Window From Another Custom Window

Hey guys, I am having a heck of a time with this one. Basically I am trying to derive a window off of another window, which is derived from the plain window shipped with WPF. I know how to derive from in in code but the problem is using it in the xaml. I have done what I have so far found in the inet. This is really the only thing I have seen referring to it on my searches

<src:myForm
<!--Other Goodies, Intentional space, get a smile if not-->
xmlns: src="clr-namespace:mynamespace;assembly=myassembly"
>
</>

The problem with that is I get this error upon compiling

cannot be the root of a XAML file because it was defined using XAML. Line 2 Position 2.

As well as some other messages regarding schema(not errors). What am I missing because this is driving me nuts.

[828 byte] By [Prog-Bman] at [2008-1-5]
# 1
Looks like basically you're trying to say to XAML:

  1. The root element is myForm within the namespace I defined as src.
  2. I want to define a namespace called src that is located at ...
I imagine XAML can't get past step one to process step two.

I'm not aware of any way to define a namespace before the root node, but it might be possible using metadata. Otherwise, I think you're pretty much messed as far as declaring a CustomWindow in XAML. Code should be well enough, but that defeats the point.

MattEland at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 2
So basically there is no inheritance for windows in WPF(xaml), because that makes no sense and is quite lame. Anyone else have a suggestion on how to go about this, there has to be some sort of a workaround or something for the time being
Prog-Bman at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 3
Well, what do you need a custom Window object for? Is it for styling, added methods, or what?

If you really can't extend Windows and reference them as root nodes in XAML (which does seem pretty lousy to me), there might be another way to get the functionality you're looking for.

MattEland at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 4
I basically need a window that will do some special control processing that I want all the windows in my application to inherit(formating, etc), so that I don't need some sort of external class, within each window of the application. I mean it is possible to do it that way but it just seems more easily done with some simple inheritance.
Prog-Bman at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 5

It's not that you're defining and using the namespace in the same element. The following is perfectly legal: (spaces intentional to avoid emoticons)

<Label Content="{x: Static sys: DateTime.Now}" xmlns: sys="clr-namespace: System;assembly=mscorlib"/>

But it's not possible to inherit a from a custom window in XAML. I forget the full reason why, but if I recall it has to do with how XAML is loaded. What I've done in create a class that inherits from a panel such as grid or dock panel and then use that class as the root element for all of my windows. I don't know if that will work for you though. You could also try creating a style for Window in App.xaml.

CaroleSnyder at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 6

Hello, Carole is right. You can’t inherit a Window if the parent Window is defined in XAML. But in your case, it seems that it’s not difficult to define your parent Window in pure code. So just use pure code to define your parent Window, and then you can inherit it in XAML.

Yi-LunLuo-MSFT at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified