vendredi 16 novembre 2018

Problem: WPF Checkbox inside Listbox is disabled but still clickable

I have a Style for a listbox, using checkboxes. I want to bind the isEnabled property of each checkbox to a property (ItemEnabled) of each item. This is my code:

<Setter Property="ItemContainerStyle">
            <Setter.Value>
                <Style TargetType="{x:Type ListBoxItem}" >
                    <Setter Property="Margin" Value="2" />                    
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                <CheckBox Focusable="False"                                    
                                    IsChecked="{Binding Path=IsSelected, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent} }"
                                    IsEnabled="{Binding Path=ItemEnabled, Mode=OneWay}">
                                    <ContentPresenter></ContentPresenter>
                                </CheckBox>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Setter.Value>
        </Setter>

So far, the checkboxes which have the property ItemEnabled set to false, are grayed out. However, still clickable and checkable/uncheckable. Any ideas?




Aucun commentaire:

Enregistrer un commentaire