我有一个WPF应用程序和一个窗口。假设我的xml文件中有以下内容:
<Label Name="TitleLabel" Content="Some title" \>
<Label Name="BottomLabel" Content="{Binding ElementName=TitleLabel Path=Content">
假设我不能使用 XML 来创建 BottomLabel 和 TitleLabel。因此,我必须在我的 "Code behind" 中将 BottomLabel 创建为属性。如何在我的 "Code behind" 中为 Bottom label 的 Content 属性指定相同的绑定?是否有可能实现?
因此,我会有类似这样的内容:
public Label TitleLabel {get; private set;}
public Label BottomLabel {get; private set;}
public MyClass(){
TitleLabel = new Label();
TitleLabel.Content = "Some title";
BottomLabel = new Label();
BottomLabel.Content = // ?? what should be here ? How do I specify the binding
// that binds BottomLabel.COntent to TitleLabel.Content?
}
我可以写什么代替评论? 谢谢您的回答。
BindingOperations.SetBinding()
,因为我的目标对象是AnimationTimeline
类型。我认为我可以弄清楚如何做,但您能否为这种情况提供示例呢?至少对于以后阅读您的答案的人来说,这将非常有用。谢谢。 - RastoTimeline.DurationProperty
)。 - Julien Lebosquain