尝试的结合
// 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