2012-11-14 123 views
0

有没有办法在代码中获取下面定义的组合框的文本属性的DataContent?有没有办法让一个绑定的属性DataContext

<ComboBox Height="21" Text="{Binding Path=Field1.Value}"> 
     <ComboBox.Resources> 
      <Style TargetType="ComboBox"> 
       <Setter Property="IsEnabled" Value="False" /> 
       <Style.Triggers> 
        <DataTrigger Binding="{Binding Path=Field2.Value}" Value=""> 
         <Setter Property="IsEnabled" Value="True" /> 
        </DataTrigger> 
       </Style.Triggers> 
      </Style> 
     </ComboBox.Resources> 
    </ComboBox> 

当前ComboBox的DataContext是它所在的用户控件。这是有道理的,因为我想我的文本绑定到一个属性,我的DataTrigger绑定到另一个属性。但我需要获取绑定到Text属性的DataContext。

回答

1

像这样的东西应该这样做:

Binding binding = BindingOperations.GetBinding(yourComboBox, ComboBox.TextProperty); 
object theDataContext = binding.Source; 
+0

是该做的。这是另一个我以前找不到的答案。 [链接](http://stackoverflow.com/questions/4051360/in-wpf-how-to-get-binding-of-a-specific-item-from-the-code) – FodderZone

相关问题