Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all.

I have a base C# class (EditorButton) that inherits from Button with a corresponding xaml file set in generics.

I have a derived XAML class from the Editor button and the XAML sets properties in the markup (the content)(Like Delete, Cut, Clear, Duplicate)

When I'm creating a new derived class (Delete) to insert into the editor control, none of the content shows up. (when I look at the properties in the code, everything is null)

The images and properties appear in the XAML editor. I'm stumped and lost as to even properly ask the question.

Here's the essentials of the c# class

C#
[DesignTimeVisible(true)]
    public partial class EditorButton : Button
    {

        public static readonly DependencyProperty IsCheckedProperty;

        public bool IsChecked
        {
            get
            {
                return (bool)GetValue(EditorButton.IsCheckedProperty);
            }
            set
            {
                SetValue(EditorButton.IsCheckedProperty, value);
            }
        }

        static EditorButton()
        {
            FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(typeof(EditorButton),
                                                          new FrameworkPropertyMetadata(typeof(EditorButton)));
            EditorButton.IsCheckedProperty = DependencyProperty.Register("IsChecked", 
                                                                         typeof(bool), 
                                                                         typeof(EditorButton), 
                                                                         new FrameworkPropertyMetadata(false, 
                                                                                                       FrameworkPropertyMetadataOptions.AffectsRender));
        }

        public EditorButton()
        {
        }

        
    }


The XAML File:
XML
<titan:EditorButton
     x:Class="Titan.Controls.EditorClearButton"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:titan="clr-namespace:Titan.Controls"
    
    Focusable="false" BorderThickness="5">
       <Image Name="ClearImage"
             Source="/Titan;component/images/Clear.png"
             Stretch="None"
             SnapsToDevicePixels="True"/>

</titan:EditorButton>
Posted
Comments
Per Söderlund 4-Sep-12 2:20am    
I´m just guessing here so don´t take this too serious.
I don´t think you can derive from a base class that has XAML in it.
So you should create a baseclass with C# code only and after that you can derive more controls using XAML.
darshan_ur 4-Sep-12 6:23am    
I think Soderlund is correct, you cannot derive from a base class with XAML.
But if you want to have the mentioned functionality you should try creating a Usercontrol that inherits from Button and reuse the user control.
Hope this helps you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900