Reputation: 5420
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>
Upvotes: 0
Views: 32
Reputation: 24453
The Binding
in your DataTrigger
isn't set up correctly. You've assigned the Binding
a Path
of CB1.SelectedItem
so it is looking at whatever the current DataContext
is for a property named CB1
and then a SelectedItem
property on that object. You've also included an UpdateSourceTrigger
setting which, while not breaking anything, is meaningless in this instance (it is used to determine when to push changes to the Source with a TwoWay
or OneWayToSource
binding usually on an input control).
To bind to another control within the same namescope use ElementName
to specify the control and Path
to specify the property:
<DataTrigger Binding="{Binding ElementName=CB1, Path=SelectedItem}" Value="{x:Null}">
Upvotes: 1