Inheriting from inherited user controlI'm having a problem with a user control generated code, when it inherits from other than UserControl.<br><br>Steps:<br>1. Add new User control<br>2. Replace in the inheritance declaration UserControl for MyBaseUserControl<br>3. Compile<br><br>The generated class part is still inheriting from UserControl.<br>You can change the &quot;.g.cs&quot; file, and sometimes you can get it succesfully compiled, but the error cames back again and again :)<br><br>There is another way to do that?<br>Thanks in advance...<br>© 2009 Microsoft Corporation. All rights reserved.Thu, 19 Jun 2008 00:15:52 Z574ace23-3cb7-4d4e-a8be-d00c97110bedhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/574ace23-3cb7-4d4e-a8be-d00c97110bed#574ace23-3cb7-4d4e-a8be-d00c97110bedhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/574ace23-3cb7-4d4e-a8be-d00c97110bed#574ace23-3cb7-4d4e-a8be-d00c97110bedleovernazzahttp://social.msdn.microsoft.com/Profile/en-US/?user=leovernazzaInheriting from inherited user controlI'm having a problem with a user control generated code, when it inherits from other than UserControl.<br><br>Steps:<br>1. Add new User control<br>2. Replace in the inheritance declaration UserControl for MyBaseUserControl<br>3. Compile<br><br>The generated class part is still inheriting from UserControl.<br>You can change the &quot;.g.cs&quot; file, and sometimes you can get it succesfully compiled, but the error cames back again and again :)<br><br>There is another way to do that?<br>Thanks in advance...<br>Thu, 06 Jul 2006 04:22:10 Z2006-07-10T19:17:58Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/574ace23-3cb7-4d4e-a8be-d00c97110bed#82bee4c5-9967-4154-a5b3-ca5c5346dd03http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/574ace23-3cb7-4d4e-a8be-d00c97110bed#82bee4c5-9967-4154-a5b3-ca5c5346dd03Marc Larochehttp://social.msdn.microsoft.com/Profile/en-US/?user=Marc%20LarocheInheriting from inherited user controlQuick question:<br><br>Have you changed Root XAML node of the MyBaseUserControl.xaml file to MyBaseUserControl as well? <br><br>Let me know!!!<br><br><br>Thu, 06 Jul 2006 12:36:42 Z2006-07-10T19:17:58Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/574ace23-3cb7-4d4e-a8be-d00c97110bed#3cfc5633-8c03-473e-b985-d0cfb7e0c7f7http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/574ace23-3cb7-4d4e-a8be-d00c97110bed#3cfc5633-8c03-473e-b985-d0cfb7e0c7f7leovernazzahttp://social.msdn.microsoft.com/Profile/en-US/?user=leovernazzaInheriting from inherited user controlYes, it was the first problem. :S<br><br>But then I get: &quot;<span style="font-weight:bold">Error 7 'MyBaseUserControl' cannot be the root of a XAML file because it was defined using XAML.</span>&quot;<br><br>I can get it working if I convert it to a CustomControl (no xaml definition), but I loose the declarative inheritance.... mmm... I suppose I still can use templates and styles to reach that.<br><br>Is this a XAML &quot;design decision&quot;?<br>Thu, 06 Jul 2006 22:11:51 Z2006-07-06T22:11:51Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/574ace23-3cb7-4d4e-a8be-d00c97110bed#b8583e6b-069d-40da-bd32-c2ad0ab3b953http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/574ace23-3cb7-4d4e-a8be-d00c97110bed#b8583e6b-069d-40da-bd32-c2ad0ab3b953Ed Noepelhttp://social.msdn.microsoft.com/Profile/en-US/?user=Ed%20NoepelInheriting from inherited user controlThis seems to be a very important question for which I cannot find an answer.  Can a component defined in XAML be subclassed? <a title="http://geekswithblogs.net/lbugnion/archive/2007/03/02/107747.aspx" href="http://geekswithblogs.net/lbugnion/archive/2007/03/02/107747.aspx">This blog post</a> asserts it can be done, but I have not found a way to get it to work.  Like everyone else, I get the following compile-time error when I try to subclass a Window I defined in XAML.<br><br><font size=2><span style="font-family:Courier">error MC6017: 'MyCustomWindow' cannot be the root of a XAML file because it was defined using XAML.<br><br><span style="font-family:Arial"><span style="font-style:italic">If </span>we cannot subclass Windows defined in XAML, what are the best practices for coupling a base window style with common window functionality throughout an application?<br></span></span></font>Tue, 02 Oct 2007 17:44:02 Z2007-10-02T17:44:02Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/574ace23-3cb7-4d4e-a8be-d00c97110bed#03381a8e-f8d8-40a2-9ae8-90235a85030ehttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/574ace23-3cb7-4d4e-a8be-d00c97110bed#03381a8e-f8d8-40a2-9ae8-90235a85030eSerialSeb-http://social.msdn.microsoft.com/Profile/en-US/?user=SerialSeb-Inheriting from inherited user control<p>As the error message indicates, you can inherit from a class that inherits from Window, not from a Window you've created that has a .xaml and a .cs file. The former will be perfectly acceptable as a base class, the second will not.</p> <p align=left> </p> <p align=left>If you want to define a base window style, the way to go is to create a ControlTemplate for Window, and symply apply it through a style.</p> <p align=left> </p> <p style="font-size:10pt;background:white;margin:0px;color:black;font-family:Consolas, Courier New" align=left><span style="color:blue"> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Block</span></div> <p style="font-size:10pt;background:white;margin:0px;color:black;font-family:Consolas, Courier New" align=left><span style="color:blue">&lt;</span><span style="color:#a31515">Window</span><span style="color:red"> x</span><span style="color:blue">:</span><span style="color:red">Class</span><span style="color:blue">=&quot;CaffeineIT.Blog.WindowTemplate.Window1&quot;</span></p> <p style="font-size:10pt;background:white;margin:0px;color:black;font-family:Consolas, Courier New" align=left>  <span style="color:red">xmlns</span><span style="color:blue">=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span></p> <p style="font-size:10pt;background:white;margin:0px;color:black;font-family:Consolas, Courier New" align=left>  <span style="color:red">xmlns</span><span style="color:blue">:</span><span style="color:red">x</span><span style="color:blue">=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span></p> <p style="font-size:10pt;background:white;margin:0px;color:black;font-family:Consolas, Courier New" align=left>  <span style="color:red">Title</span><span style="color:blue">=&quot;Window1&quot;</span><span style="color:red"> Height</span><span style="color:blue">=&quot;300&quot;</span><span style="color:red"> Width</span><span style="color:blue">=&quot;300&quot;&gt;</span></p> <p style="font-size:10pt;background:white;margin:0px;color:black;font-family:Consolas, Courier New" align=left><span style="color:#a31515">    </span><span style="color:blue">&lt;</span><span style="color:#a31515">Window.Template</span><span style="color:blue">&gt;</span></p> <p style="font-size:10pt;background:white;margin:0px;color:black;font-family:Consolas, Courier New" align=left><span style="color:#a31515">        </span><span style="color:blue">&lt;</span><span style="color:#a31515">ControlTemplate</span><span style="color:red"> TargetType</span><span style="color:blue">=&quot;{</span><span style="color:#a31515">x</span><span style="color:blue">:</span><span style="color:#a31515">Type</span><span style="color:red"> Window</span><span style="color:blue">}&quot;&gt;</span></p> <p style="font-size:10pt;background:white;margin:0px;color:black;font-family:Consolas, Courier New" align=left><span style="color:#a31515">            </span><span style="color:blue">&lt;</span><span style="color:#a31515">Border</span><span style="color:red"> Background</span><span style="color:blue">=&quot;Beige&quot;</span><span style="color:red"> Padding</span><span style="color:blue">=&quot;20&quot;</span><span style="color:red"> Margin</span><span style="color:blue">=&quot;20&quot;&gt;</span></p> <p style="font-size:10pt;background:white;margin:0px;color:black;font-family:Consolas, Courier New" align=left><span style="color:#a31515">                </span><span style="color:blue">&lt;</span><span style="color:#a31515">ContentPresenter</span><span style="color:blue"> /&gt;</span></p> <p style="font-size:10pt;background:white;margin:0px;color:black;font-family:Consolas, Courier New" align=left><span style="color:#a31515">            </span><span style="color:blue">&lt;/</span><span style="color:#a31515">Border</span><span style="color:blue">&gt;</span></p> <p style="font-size:10pt;background:white;margin:0px;color:black;font-family:Consolas, Courier New" align=left><span style="color:#a31515">        </span><span style="color:blue">&lt;/</span><span style="color:#a31515">ControlTemplate</span><span style="color:blue">&gt;</span></p> <p style="font-size:10pt;background:white;margin:0px;color:black;font-family:Consolas, Courier New" align=left><span style="color:#a31515">    </span><span style="color:blue">&lt;/</span><span style="color:#a31515">Window.Template</span><span style="color:blue">&gt;</span></p> <p style="font-size:10pt;background:white;margin:0px;color:black;font-family:Consolas, Courier New" align=left><span style="color:#a31515">    </span><span style="color:blue">&lt;</span><span style="color:#a31515">TextBlock</span><span style="color:blue">&gt;</span><span style="color:#a31515">Oh, I'm the content!</span><span style="color:blue">&lt;/</span><span style="color:#a31515">TextBlock</span><span style="color:blue">&gt;</span></p> <p style="font-size:10pt;background:white;margin:0px;color:black;font-family:Consolas, Courier New" align=left><span style="color:blue">&lt;/</span><span style="color:#a31515">Window</span><span style="color:blue">&gt;</span></p></div></div> <p align=left> </p></span> <p></p> <p align=left><font face=Arial size=2></font> </p>Tue, 02 Oct 2007 21:31:17 Z2007-10-02T21:31:17Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/574ace23-3cb7-4d4e-a8be-d00c97110bed#346e80c7-58ee-44b8-920c-f7e16b7cafachttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/574ace23-3cb7-4d4e-a8be-d00c97110bed#346e80c7-58ee-44b8-920c-f7e16b7cafacEd Noepelhttp://social.msdn.microsoft.com/Profile/en-US/?user=Ed%20NoepelInheriting from inherited user controlAgreed.  The ctor of my BaseWindow currently sets its own Template property to a ControlTemplate (stored in a ResourceDictionary) defining the look-and-feel.  This is because I do not want to force all Windows deriving from BaseWindow to grab the ControlTemplate from the ResourceDictionary and set it explicitly.  It is important that classes deriving from my BaseWindow use the same ControlTemplate because some code in the BaseWindow class is needed to define the look (doing things not possible in XAML alone).<br><br>The following post makes some good arguments about where inheritance should be used: <a title="http://work.j832.com/2007/06/don-subclass-panel-unless-you-making.html" href="http://work.j832.com/2007/06/don-subclass-panel-unless-you-making.html">markup subclassing</a>. In my case, I am using inheritance for more than just polymorphism.  I am doing so because I must be fascist about the look of the derived Window.<br><br><font face=Arial size=2></font><font face=Arial size=2></font><font face=Arial size=2></font><font face=Arial size=2></font>Thu, 04 Oct 2007 01:19:27 Z2007-10-04T01:19:27Z