0
votes

can you tell me what is the proper way to create custom silverlight controls? I want to make a control that consists of three other controls: textblock, autocompletebox and image. The textblock will act as a label for the autocompletebox and the image will provide additional tooltip. My question is: what type of class should I inherite from? How can I expose properties and events of the inner controls? I found that I can set values of child controls by creating additional dependency properties in the container class and using callback function like this:

public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
    "Text",
    typeof(string),
    typeof(MyCustomControl),
    new PropertyMetadata(
        default(string),
        (source, args) => (source as MyCustomControl).TxtValue.Text = (string)args.NewValue
    )
);

However this method works only if the property in the child control is declared as dependency property. But for instance in autocompletebox there is a property called ValueMemberBinding which is not a dependency property and I can't find a way how to expose this from MyCustomControl.

1

1 Answers

0
votes

My question is: what type of class should I inherite from?

You inherit from Control class.

Here is a basic tutorial.

How can I expose properties and events of the inner controls?

As for properties - if you use xaml for setting up the controls contents and layout, you need to assign an x:Name property to each element, who's properties you want to expose. Then, they bacome available in code-behind and you can expose them as public properties.

As for events, you subscribe to the events of the inner elements and link them to your controls public events.