Silverlight UserControl Custom Property Binding

前端 未结 3 1425
生来不讨喜
生来不讨喜 2021-02-07 08:36

What is the proper way to implement Custom Properties in Silverlight UserControls?

Every \"Page\" in Silverlight is technically a UserControl (they are derived from the

3条回答
  •  长情又很酷
    2021-02-07 09:11

    I understand it as the reason your control is not receiving the new value from the maim page is that you are setting the DataContext of the control. If you hadn't then the control's DataContext will be inherited from its parent, the main page in this case.

    To get this to work I removed you control's DataContext setting, added an x:Name to each control and set the binding in the constructor of the control using the [name].SetBinding method.

    I did the binding in the ctor as I couldn't figure out a way of setting the Source property of the declarative binding in the xaml to Self. i.e. {Binding SelectedText, Mode=TwoWay, Source=[Self here some how]}. I did try using RelativeSource={RelativeSource Self} with no joy.

    NOTE: All this is SL3.

提交回复
热议问题