0

basically i have 2 ComboBoxes and i want to isEnabled="false" my secound ComboBoxe2 as long as my first ComboBoxe1.Selecteditem == null

so i created the following DataTrigger

    <ComboBox Name="CB1"
              DisplayMemberPath="NameL"
              IsEnabled="{Binding isNew}"
              SelectedItem="{Binding selectedSpTyp}" 
              ItemsSource="{Binding SpTypList}"/>

    <ComboBox Name="CB2"
              DisplayMemberPath="NameD"
              SelectedItem="{Binding selectedDesginvorlage}"
              ItemsSource="{Binding DesginvorlageList}">
        <ComboBox.Style>
            <Style>
                <Setter Property="UIElement.IsEnabled" Value="True"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding CB1.SelectedItem, UpdateSourceTrigger=PropertyChanged}" Value="{x:Null}">
                        <Setter Property="UIElement.IsEnabled" Value="False"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </ComboBox.Style>
    </ComboBox>
4

1 回答 1

1

BindingDataTrigger的设置不正确。您已经分配了Bindinga Pathof ,CB1.SelectedItem因此它正在查看当前DataContext用于命名属性的任何内容CB1,然后SelectedItem查看该对象上的属性。您还包括了一个设置,虽然没有破坏任何东西,但在这种情况下是没有意义的(它用于确定何时使用或绑定通常在输入控件上将UpdateSourceTrigger更改推送到 Source )。TwoWayOneWayToSource

要绑定到同一名称范围内的另一个控件,请使用ElementName指定控件并Path指定属性:

<DataTrigger Binding="{Binding ElementName=CB1, Path=SelectedItem}" Value="{x:Null}">
于 2013-05-16T20:49:17.243 回答