且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Silverlight的用户控件自定义属性绑定

更新时间:2021-09-06 18:00:00

我把它理解为你的控制没有收到来自残废页的新值的原因是,要设置控件的DataContext的。如果你没有那么控制的的DataContext将其父在这种情况下继承,主页。

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.

要得到这个工作,我删除你控制的DataContext的设置,增加了一个X:名称给每个控制和使用[名] .SetBinding方法设置控件的构造函数的结合

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.

我确实在构造函数的结合,因为我无法弄清楚设置声明绑定的Source属性在XAML以自我的一种方式。即{[这里自一些如何]绑定SelectedText,模式=双向,源=}。我曾尝试使用的RelativeSource = {自我的RelativeSource}没有快乐。

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.

请注意:这一切都是SL3

NOTE: All this is SL3.