Article ID: 957231
RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.
You have a WPF application. You have a class such as a UserControl defined using XAML. You derive a class from the UserControl.
<CheckBox Height="16" Margin="8,30,0,0" Name="checkBox1" VerticalAlignment="Top" HorizontalAlignment="Left" Width="120">CheckBox</CheckBox>
You will get "xyz cannot be the root of a XAML file because it was defined using XAML" error.
Currently deriving a XAML generated class from another XAML generated class is not supported.
You need to define your base class all in code without using XAML.
Your derived class is not instantiated in the designer when you are designing it, which means that any calls made to your base class from the constructor are not called. Furthermore, if you try to initialize your base class's content in its constructor, you will find that Content member is still set to null.
This results in that your base class's content does not show up in the designer when you are designing your deriving class, even though it does at runtime.
One way to workaround is to add code similar to the one below in your base class:
public class UserControlInCode : UserControl
protected override void OnContentChanged(object oldContent, object newContent)
StackPanel panel = new StackPanel();
Button button = new Button();
button.Content = "Test";
This way, you wait until your base class sets Content member.
MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALS”) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.
Contact us for more help
Connect with Answer Desk for expert help.