lundi 1 juin 2020

Unable to bind wpf checkbox IsChecked to datatrigger and View Model

I have a wpf user control that has a checkbox for each day of the week and another checkbox for all days. I can set the individual days by clicking the all days check box using data triggers. However I am using caliburn micro and a view model with Notify of property change. When I add binding in any format to the view model the ischecked property stops working, the isenabled continues to work. I have tried several different bind methods without any success. I am very much self taught and trying to work things out using youtube and google but this has me stumped - should I use ivalueconverter? Here is a part of my xml code

        <CheckBox x:Name="CheckSaturdayCkBx" Content="Saturday" IsChecked="{Binding SaturdayCkBx}"
                   Grid.Row="1" Grid.Column="3">
            <CheckBox.Style>
                <Style TargetType="{x:Type CheckBox}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ElementName=AllDaysCkBx,Path=IsChecked}" Value="True">
                            <Setter Property="IsChecked" Value="True"/>
                            <Setter Property="IsEnabled" Value="False"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </CheckBox.Style>
        </CheckBox>

        <CheckBox x:Name="SundayCkBx" Content="Sunday"
                   Grid.Row="2" Grid.Column="3">
            <CheckBox.Style>
                <Style TargetType="{x:Type CheckBox}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ElementName=AllDaysCkBx,Path=IsChecked}" Value="True">
                            <Setter Property="IsChecked" Value="True"/>
                            <Setter Property="IsEnabled" Value="False"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </CheckBox.Style>
        </CheckBox>

        <CheckBox x:Name="AllDaysCkBx" Content="All Days"
                   Grid.Row="4" Grid.Column="3"/>

The property SaturdayCkBx and SundayCkBx are bound to the view model I need these if I want to load data from a database table. I have above tried two variations without any joy - remove these bindings to view model and it works. Any help pointers very much appreciated.




Aucun commentaire:

Enregistrer un commentaire