1

How can I expand an existing class, with additional properties, methods, or functions? So that I can use them in the XAML code? I would like to extend the AlavonDock library and add more functionality to the existing classes.

That's precise what I mean: The AvalonDock.dll should to contain, in class LayoutItem a further Property: SubTitle. I wouldn't like to edit the existing classes (in the AvalonDock library). But I want to create my own dll which extends the functionality of AvalonDock.dll.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
peter70
  • 1,053
  • 16
  • 31

2 Answers2

0

Just extend the relevant class like you would any other class:

using AvalonDock; // or whatever the dll is called

public class ExtendedClass : OriginalClassToExtend
{
    private string subTitle = string.Empty;

    public ExtendedClass() : base()
    {
        // Add new functionality to constructor
    }

    public string SubTitle { get; set; }
}

Please take a look at the Inheritance (C# Programming Guide) page on MSDN for more help.

Sheridan
  • 68,826
  • 24
  • 143
  • 183
  • can I initialize an `ExtendedClass` instance based on `OriginalClassToExtend` instance? Add SubTitle and return? – Toolkit Mar 20 '17 at 18:23
  • I'm not sure what you mean by 'initialize an `ExtendedClass` instance based on `OriginalClassToExtend` instance', but this follows all the polymorphism rules that any extended class follows. Therefore, you could cast an `OriginalClassToExtend` instance to an `ExtendedClass` instance and set the `SubTitle` property on it. – Sheridan Jun 15 '17 at 15:30
0

Implement your own class that derives from AvalonDock classes and add whatever functionality as you would like

public class MyLayoutItem : LayoutItem
{
    public string SubTitle 
    {
         get { return (string)this.GetValue(SubTitleProperty); }
         set { this.SetValue(SubTitleProperty, value); } 
    }

    public static readonly DependencyProperty SubTitleProperty = DependencyProperty.Register("SubTitle", typeof(string), typeof(MyLayoutItem),new PropertyMetadata(string.Empty));
}
Omri Btian
  • 6,499
  • 4
  • 39
  • 65
  • I have created an example with an app and two libs. My wrapper class, in the second dll, inherits from a class in the first lib. In XAML of the app, I try to create an element of the second class: . This can not be instanciated, but the class in my second lib have not a ressource that in first lib (usercontrol) was have identified – peter70 Oct 03 '13 at 11:00
  • This is the original message: The component "ThemeEarthLibrary.ADWrapper" does not have a resource that is identified by the URI "/AvalonDock;component/yellowedit.xaml". – peter70 Oct 03 '13 at 11:02
  • @peter70 What is your xmlns of `sc`? – Omri Btian Oct 03 '13 at 11:25