Passing parameters to custom control (databinding)

573 views Asked by At

I want to create a custom control with 2 parameters to be databindable. The parameters are ExchangeCode and TickerCode

Currently, here is what I am trying (which doesn't work) :

This is my custom control

public partial class Graph : UserControl
{
    public Graph()
    {
        InitializeComponent();
    }

    public static readonly DependencyProperty ExchangeCodeProperty = DependencyProperty.Register
                (
                     "ExchangeCode",
                     typeof(string),
                     typeof(Graph),
                     new PropertyMetadata(string.Empty)
                );

    public string ExchangeCode
    {
        get { return (string)GetValue(ExchangeCodeProperty); }
        set { SetValue(ExchangeCodeProperty, value); }
    }

    public static readonly DependencyProperty TickerCodeProperty = DependencyProperty.Register
                (
                     "TickerCode",
                     typeof(string),
                     typeof(Graph),
                     new PropertyMetadata(string.Empty)
                );

    public string TickerCode
    {
        get { return (string)GetValue(TickerCodeProperty); }
        set { SetValue(TickerCodeProperty, value); }
    }
}

This is the XAML in an other control

<grph:Graph TickerCode="ILD" ExchangeCode="EPA"/>

For now I didn't really bind data, but basically at the end it will be something like "{Binding Panes.TickerCode}" and "{Binding Panes.ExchangeCode}" but my ViewModel is not fully finished and I want to test how the parameters are passed so far.

So doing this, my custom control is properly added to the other custom control that calls it, but no ExchangeCode nor TickerCode is passed.

What am I missing?

Thank you all in advance, your help will be greatly appreciated.

0

There are 0 answers