Passing parameters to custom control (databinding)

僤鯓⒐⒋嵵緔 提交于 2019-12-13 19:09:42

问题


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.

来源:https://stackoverflow.com/questions/30816114/passing-parameters-to-custom-control-databinding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!