嘗試的結合
// UserControl DataContext={Binding SomeDataContext } Suppose here UserControl starts
<!--Bind Height with Width of SameControl-->
<TextBox Name="textBox1" Height="{Binding Width, RelativeSource={RelativeSource Mode=Self}}"/>
<!--Bind Height to the VMProperty in the DataContext of Window-->
<TextBox Name="textBox2" Height="{Binding DataContext.VMProperty, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"/>
<!--Bind Height with the Width of first textbox-->
<TextBox Name="textBox3" Height="{Binding Width, ElementName=textBox1}"/>
<!--bind Height with the UserControlDataContextProperty in UserControl DataContext-->
<TextBox Name="textBox4" Height="{Binding UserControlDataContextProperty}"/>
//Here UserControl ends
以上是許多類型的結合下面的方式之一。你可以使用一個適合你的要求。我希望這會有所幫助。
你的意思是你想要將UserControl的2個屬性綁定到UserControl的DataContext的屬性中,並將其他屬性綁定到Window的DataContext中的屬性。 – ethicallogics 2012-07-18 14:11:25
爲了簡化問題,我有一個帶有DependencyProperty和Data上下文的UserControl。我怎樣才能綁定DependencyProperty與datacontext的一些屬性? – Louro 2012-07-18 14:36:46