Wpf combobox selection change breaks Datatrigger
Posted
by biju
on Stack Overflow
See other posts from Stack Overflow
or by biju
Published on 2010-04-09T07:03:25Z
Indexed on
2010/04/10
5:13 UTC
Read the original article
Hit count: 818
Hi, I am trying to set the selected value of a combobox from a style trigger.It works as long as we dont manually change any value in the combobox.But it stops working altogether after manually changing the selection.How can i solve this.A sample code is attached.Please do help
<Window x:Class="InputGesture.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:InputGesture"
Title="Window2" Height="300" Width="300" Name="Sample">
<Window.Resources>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="ComboBox.SelectedValue" Value="1"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=chk,Path=IsChecked}" Value="True">
<Setter Property="ComboBox.IsEnabled" Value="False"/>
<Setter Property="ComboBox.SelectedValue" Value="2"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<StackPanel>
<CheckBox Name="chk" Height="23"/>
<ComboBox Name="cmb" Height="23" DisplayMemberPath="Name"
SelectedValuePath="Id" ItemsSource="{Binding ElementName=Sample,Path=DT}">
</ComboBox>
<Button Height="23" Click="Button_Click"/>
</StackPanel>
</Window>
© Stack Overflow or respective owner