Microsoft Developer Network > 포럼 홈 > Windows Presentation Foundation (WPF) > Deriving A Window From Another Custom Window
질문하기질문하기
 

답변됨Deriving A Window From Another Custom Window

  • 2007년 6월 16일 토요일 오전 1:19Prog-Bman 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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.

답변

  • 2007년 6월 18일 월요일 오후 3:41Carole Snyder - MSFT 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    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.

  • 2007년 6월 20일 수요일 오전 6:19Yi-Lun LuoMSFT, 중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    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.

모든 응답

  • 2007년 6월 16일 토요일 오전 4:11Matt Eland 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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.
  • 2007년 6월 16일 토요일 오후 9:45Prog-Bman 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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
  • 2007년 6월 16일 토요일 오후 11:16Matt Eland 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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.
  • 2007년 6월 17일 일요일 오후 10:16Prog-Bman 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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.
  • 2007년 6월 18일 월요일 오후 3:41Carole Snyder - MSFT 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    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.

  • 2007년 6월 20일 수요일 오전 6:19Yi-Lun LuoMSFT, 중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    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.

  • 2008년 1월 30일 수요일 오후 9:57the_magic_juan 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    I think MSFT really missed the boat on this one and I hope they fix it...to not be able to inherit xaml is a big miss.  I know somebody is going to say, "just use styles".  What we want to do, declaritively define a base xaml page with wpf controls including the excellent xceed datagrid with events and what not...that's not styles.  wpf is right on for the designer but for shops that are trying out wpf, to not be able to inherit a base xaml page, defined declaritively, defeats the purpose of oop.  I understand that you can create the page all in code and then have your wpf page inherit that.  That's great.  But then you loose the ease and power of the xaml.  I can dynamically generate a xaml page at run time but that does nothing for me in design time.

     

    Anyway, I hope MSFT addresses this.  For the time being we're going to have to go back to winforms and use the host object for presenting wpf - sort of a hybrid application.

     

    Thanks.