질문하기질문하기
 

답변됨UserControl Inheritance

  • 2008년 3월 26일 수요일 오전 11:36Vijay.Greypad 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Hi,

    I have two UserControls
    1.UserControl1
    2.UserControl2

    how to inherit Usercontrol1 in UserControl2.

    Please give me some idea about this.

    Regards,
    Vijay

답변

  • 2008년 3월 28일 금요일 오전 2:30Marco Zhou 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    In current version of WPF, you cannot subclass from XAML generated classes, you need to do it in code instead something like the following should work:

    Code Snippet

    public class Parent : UserControl
    {
    }

    <src:Parent x:Class="Test.Child"
                     xmlns:src="clr-namespace:Test"
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"/>


    Hope this helps

모든 응답

  • 2008년 3월 26일 수요일 오후 4:16Denis Vuyka 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    public class UserControl2 : UserControl1

    {

    }

     

    I think this question is more related to the basics of object oriented programming and you should really refer to the appropriate forums or you simply didn't cover your issue within the question.

     

  • 2008년 3월 27일 목요일 오전 4:18Vijay.Greypad 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Hi Desnis Vuyka,

    You are correct.In CS file you will do like this.

    public class UserControl2 : UserControl1

    {

    }

    But what about in Xaml.I did like this

    In UserControl1.Xaml
    <UserControl x:Class="MDIWindows.Parent"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Height="300" Width="300">

    </UserControl>

    In UserControl2.Xaml
    <srcUserControl1 x:Class="MDIWindows.Child"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlnsTongue Tiedrc="clr-namespace:MDIWindows"
        Height="300" Width="300">
     
    </src:UserControl1>

    Here i am getting error.
    Please me about this.


    Regards.


  • 2008년 3월 28일 금요일 오전 2:30Marco Zhou 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    In current version of WPF, you cannot subclass from XAML generated classes, you need to do it in code instead something like the following should work:

    Code Snippet

    public class Parent : UserControl
    {
    }

    <src:Parent x:Class="Test.Child"
                     xmlns:src="clr-namespace:Test"
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"/>


    Hope this helps
  • 2008년 5월 12일 월요일 오전 8:56bootis 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Dear all,

    I have a question about all this: how to develop my controls for the moment ?

    As inheritance with XAML generated classes does not work, i don't know whether I should
    programmatically declare all my "generic" controls in the base class, or abandon this idea of common controls and duplicate XAML declarations...

    Actually the question could be: should I design my controls as if a future WPF release would support XAML base-classes, and wait for this next release with a temporary solution ?

    What is your opinion about this ?
  • 2008년 5월 13일 화요일 오전 7:18bootis 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    No answer... Is my question stupid? (don't hesitate...), and if yes: why?
  • 2008년 5월 13일 화요일 오전 11:38Rob Relyea중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    3.5sp1 is the next release (just went to Beta).  It hasn't yet fixed this problem.

    I'm unsure if the release after that will support it.

     

    I recommend you plan to proceed without it for anywhere from 1 - 3 years...I can't promise when we will address...

     

    Thanks, Rob

    Rob Relyea | Program Manager, WPF & Xaml Language Team
    robrelyea.com | /blog | /wpf | /xaml

  • 2008년 5월 13일 화요일 오전 11:54bootis 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Thanks much for your answer.
    The most important is that you planned to fix the problem someday...
  • 2008년 6월 17일 화요일 오후 3:03Brownie PointsMVP, 중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    Just curious what are you trying to do in this case? Do you want the child control to have the exact same look as its parent but have different functionality? Or do you want to add additional controls to the child that weren't on the parent?

  • 2009년 7월 2일 목요일 오후 2:13dayanandavt 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Go to ____.
  • 2009년 7월 7일 화요일 오후 1:47rgregoryTSC 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    I have done what you did in UserControl2.Xaml with some success.   You need to add a namespace where your UserControl1 is defined.  See below

    <src:UserControl1 x:Class="MDIWindows.Child"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlnsTongue Tiedrc="clr-namespace:MDIWindows"
        xmlns:srs="myNamespace"
        Height="300" Width="300">
     
    </src:UserControl1>

    This approach will compile and execute, but will not display correctly in the Visual Studio Designer.  I believe this is a bug.
    Your Solution Build will succeed, even though you will get an error when you try to update the Designer window.

  • 2009년 9월 12일 토요일 오전 10:28Svetoslav Savov 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달