Ask a questionAsk a question
 

AnswerInherited Form in WPF

  • Tuesday, February 12, 2008 9:50 AMBilal Haidar - MVP Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    In Windows Forms, I usually create a parent Windows Form as a Master Form, then create Forms inherting from thast master form.

    How to do the same in WPF?

     

    Thanks a lot,

    Regards

Answers

  • Friday, February 15, 2008 1:56 AMMarco Zhou Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Bilal,

    You could pick up the RibbonStyle sample I wrote a while ago to learn about how to create inherited window in WPF.

    Hope this helps

  • Friday, February 15, 2008 8:02 AMMarco Zhou Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    As I've said that You cannot subclass from XAML generated class in current version of WPF, so basically the type of feature you are requesting is not supported and I think will not be supported in the future, since control templating is WPF's way of doing things in this regard

    Hope this helps

All Replies

  • Thursday, February 14, 2008 3:30 AMMarco Zhou Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    You can use the same trick, but one thing you need to know is that in current version of WPF, you cannot subclass from XAML generated base class.

    Hope this helps
  • Thursday, February 14, 2008 7:39 PMBilal Haidar - MVP Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Thanks for the reply!

    Can you show me the process of how to do the templating stuff with WPF? I mean, If I create a new WPF window there is no "Inherited Windows" in VS 2008. Can you guide please!

     

    Thanks a lot,
    Regards

     

  • Thursday, February 14, 2008 8:04 PMrvGraham Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Just a stab here, as I'm also a newbie at WPF (though not newbie in C#)...

     

    I think what Marco means is that anything declared with xaml, (including the window) can be declared in c#, and would need to be that way for inheritance to work.

     

    So instead of:

    <CheckBox Height="16" Margin="72,0,86,88" Name="checkBox1" VerticalAlignment="Bottom">CheckBox</CheckBox>

    in Xaml,

     

    You'd need:

    CheckBox CheckBox1 = new CheckBox();

    etc, in the C# code file. Only things declared in the C# file would be inherited.

     

    I'm sure someone will pop in with more, just trying to contribute a bit.

     

    Bob

     

     

  • Friday, February 15, 2008 1:56 AMMarco Zhou Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Bilal,

    You could pick up the RibbonStyle sample I wrote a while ago to learn about how to create inherited window in WPF.

    Hope this helps

  • Friday, February 15, 2008 7:21 AMBilal Haidar - MVP Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    Thanks Marco,

    As I saw from the example, it is not a UI inheritance, rather a class inheritance. I know that the UI inheritance was done through code, but I thought it was similar and simple like it was during the Windows Forms.

     

    Thanks again.

  • Friday, February 15, 2008 8:02 AMMarco Zhou Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    As I've said that You cannot subclass from XAML generated class in current version of WPF, so basically the type of feature you are requesting is not supported and I think will not be supported in the future, since control templating is WPF's way of doing things in this regard

    Hope this helps
  • Friday, February 15, 2008 10:04 AMBilal Haidar - MVP Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Thanks Marco a lot for your help. Much appreciated. I will definitely look at the Control Templating!

     

    I just need to ask one more question, I can see that, the actual size of a Form sometimes is not the same as the one at compile time. In WPF I see that the designer doesn't reflect what is really there in the application at runtime. I noticed that while reading in the book Professional WPF from Apress, there was an example about Photo Gallery, at design time it shows a shrinked Form and at runtime I see a full application.

     

    Can you guide on this?

    Thanks

     

  • Friday, February 15, 2008 10:22 AMMarco Zhou Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Well, you'd better ask this question at Cider designer forum instead, our product team members are actively monitoring that forum, so you would have better chance to get a good answer:
    http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=169&SiteID=1

    Hope this helps