vendredi 22 juillet 2016

WPF deselect ComboBox with CheckBox

I am using DataTrigger to deselect ComboBox with CheckBox (Unchecked == deselected). What i Need is: 1. when i select some item from ComboBox then CheckBox need to become Checked. 2. When i uncheck CheckBox then ComboBox need to deselect. 3. CheckBox cannot be checked if ComboBox is deselected (or if ComboBox is deselected after CheckBox is Checked ComboBox should be selected with first item)

Here is XAML (this is working version and need to be changed). Solution must be pure XAML (no C# code)!

                                                            <Setter Property="FlowDirection" Value="RightToLeft" />
                                                            <!--<Setter Property="IsChecked" Value="True" />
                                                            <Style.Triggers>
                                                                <DataTrigger Binding="{Binding SelectedItem, ElementName=comboBoxEventDevice, UpdateSourceTrigger=PropertyChanged}" Value="{x:Null}">
                                                                    <Setter Property="IsChecked" Value="False" />
                                                                </DataTrigger>
                                                            </Style.Triggers>-->
                                                        </Style>
                                                    </CheckBox.Style>
                                                    <ComboBox x:Name="comboBoxEventDevice" FlowDirection="LeftToRight" SelectionChanged="comboBoxEventDevice_SelectionChanged" Width="Auto">
                                                        <ComboBox.Style>
                                                            <Style TargetType="{x:Type ComboBox}" BasedOn="{StaticResource {x:Type ComboBox}}">
                                                                <Setter Property="SelectedIndex" Value="1" />
                                                                <Style.Triggers>
                                                                    <DataTrigger Binding="{Binding Path=IsChecked, RelativeSource={RelativeSource AncestorType={x:Type CheckBox}}}" Value="True">
                                                                        <Setter Property="SelectedIndex" Value="0" />
                                                                    </DataTrigger>
                                                                    <!--<DataTrigger Binding="{Binding Path=IsChecked, RelativeSource={RelativeSource AncestorType={x:Type CheckBox}}}" Value="False">
                                                                        <Setter Property="SelectedIndex" Value="1" />
                                                                    </DataTrigger>-->
                                                                </Style.Triggers>
                                                            </Style>
                                                        </ComboBox.Style>
                                                    </ComboBox>
                                                </CheckBox>




Aucun commentaire:

Enregistrer un commentaire