0

I have a custom WPF control - essentially a combo-box with check-boxes. The combo-boxes are successfully bound to a list of available items.

This control is to represent a field on a form. It is possible for the form to be completed already, in which case, the control must be rendered with the selected items - i.e. any items previously selected must be rendered as a checked CheckBox; it is here I'm running into trouble.

My first thought was to simply bind the IsChecked property - I don't think this can be done as the list of currently-selected-items is different from the list of available items which the ComboBox is bound to.

Basically, how do I gain access to the CheckBox object to set the Checked property to true? I've looked into this extensively and I can't fathom this out.

I'm using the ItemContainerGenerator approach - so when the user clicks on the drop-down, it is intended that a handler will iterate through the CheckBoxes and set the relevant boxes to checked.

Here's the XAML:

<ComboBox x:Name="FieldOptions" 
            ItemsSource="{Binding}" 
            HorizontalAlignment="Stretch" 
            Height="30"
            KeyDown="FieldOptions_OnKeyDown">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <CheckBox Name="checkbox"
                      Content="{Binding Path=Text}" 
                      Uid="{Binding Path=ID}"
                      FontStyle="Normal"
                      Foreground="Black"
                      Checked="CheckBox_OnChecked" />
            </DataTemplate>
   </ComboBox.ItemTemplate>

Any thoughts would be much appreciated.

4

0 回答 0