WPF (XAML) Visual Inheritance - by Umit Gunduz

Status : 

  Won't Fix<br /><br />
		Due to several factors the product team decided to focus its efforts on other items.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


61
4
Sign in
to vote
ID 289715 Comments
Status Closed Workarounds
Type Bug Repros 24
Opened 7/30/2007 1:20:31 PM
Access Restriction Public

Description

I can make very simple inheritance with wpf
Example:

Page1.xaml

<Page x:Class="WpfBrowserApplication2.Page1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Page1" Height="300" Width="300">
    <Grid>
        <Button Height="44" Margin="42,59,85,0" Name="button1" VerticalAlignment="Top" Click="button1_Click">Button</Button>
        <Label Margin="26,137,33,105" Name="label1">Label</Label>
    </Grid>
</Page>

Page1.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfBrowserApplication2
{
    /// <summary>
    /// Interaction logic for Page1.xaml
    /// </summary>
    public partial class Page1 : Page
    {
        public Page1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            this.NavigationService.Navigate(new Page2());
        }
    }
}

and add new Page is Page2

Page2.xaml

<l:Page1 x:Class="WpfBrowserApplication2.Page2"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:l="clr-namespace:WpfBrowserApplication2"
    Title="Page2">
    <Grid>
        
    </Grid>
</l:Page1>

Page2.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfBrowserApplication2
{
    /// <summary>
    /// Interaction logic for Page2.xaml
    /// </summary>
    public partial class Page2 : Page1
    {
        public Page2()
        {
            InitializeComponent();
        }
    }
}

this is very simple inheritance

But when i compile project after than i get errors!!!

Errors:
1: Designer tells me : The document root element is not supported by visual designer
2:Compiler tells me: 'WpfBrowserApplication2.Page1' cannot be the root of a XAML file because it was defined using XAML. 

But compiler is warning to me :

'WpfBrowserApplication2.Page2.InitializeComponent()' hides inherited member 'WpfBrowserApplication2.Page1.InitializeComponent()'. Use the new keyword if hiding was intended.

this problem was all wpf extentions. I hope that is fix in visual studio 2008 but i see that isn't fixed for wpf visual inheritance

Thanks.

Sign in to post a comment.
Posted by Microsoft on 4/13/2012 at 2:25 PM
Thanks for your feedback. At this time we will not be making any changes to this feature area in WPF.

WPF Team
Posted by Prism2407 on 4/5/2010 at 8:40 PM
Visual Inheritance worked fine till Windows Forms... Please don't stop it in WPF.

Thanks
Posted by Daniel Smith on 7/16/2009 at 1:25 AM
I really wish basics like visual inheritance could be sorted out - this is yet another area where WPF falls flat on its face compared to WinForms.
Posted by Moby Disk on 2/25/2009 at 1:41 PM
I tried this in VS2008SP1 using Window instead of Page, and I get a compiler error:
'WPFApplication.Window1' cannot be the root of a XAML file because it was defined using XAML.
It seems like this is expressly forbidden now.
Posted by Umit Gunduz on 1/25/2008 at 3:32 PM
Hi anybody, this problem continue visual Studio 2008 release.
Bob file is there
http://www.4shared.com/dir/5460229/129abcda/WPF_Visual_Inheritance_Problem.html
And i say repeat, this problem very important missing for WPF.
Posted by Togar on 11/12/2007 at 9:03 AM
I can't download the two file. There is no url to click on.

Thanks you
Posted by SerialSeb- on 8/17/2007 at 3:10 AM
If I'm not mistaken, the issue is not inheriting fro Page1 in the Page2 code-behind, it's the XAML designer not wanting anything it doesn't know as a base. From waht I remember of working with the previous cider version on vs2005 this was working (we uysed to have different page base classes defined in XAML). This also prevents inheriting from Page, and adding properties that can be set from within the Page declaration itself. The same applies to UserControls. This is a limiting factor and will probably break some applications out there.
Posted by Umit Gunduz on 7/31/2007 at 6:22 AM
Visual Inheritance very important for us. Because we are using Model-View-Presenter design pattern and write GUI framework with WPF. We solve visual inheritance with different method but this not good solution we are only show what we are showing in runtime, developers cant see in design time this.

For example us solve attached

Thanks.
Posted by Microsoft on 7/30/2007 at 5:33 PM
Thank you for your feedback. We are currently investigating. If this issue is urgent, please call support directly (see http://support.microsoft.com).

Thank you,
Visual Studio Product Team