0

以下に定義されているComboBoxのTextプロパティのDataContentを取得する方法はコードにありますか?

    <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は、それが存在するユーザーコントロールです。Textを1つのプロパティにバインドし、DataTriggerを別のプロパティにバインドする必要があるため、これは理にかなっています。ただし、TextプロパティにバインドされているDataContextを取得する必要があります。

4

1 に答える 1

1

このような何かがそれを行う必要があります:

Binding binding = BindingOperations.GetBinding(yourComboBox, ComboBox.TextProperty);
object theDataContext = binding.Source;
于 2012-11-14T19:23:50.000 に答える