WPF, ListBox's ItemTemplate has CheckBox, but CheckBox does not seem to be the item

I just wanted the CheckListBox I used to use with Windows Forms.

    <ListBox>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <CheckBox  Content="{Binding Name}"/>
            </DataTemplate>
        </ListBox.ItemTemplate>

At first this seemed to work, but there was numerous problems. In short, it just works like a CheckBox is floating on the real item, rather than the CheckBox is the item.

I mean, (1)clicking the checkbox's text would not select the ListBox item, (2)pressing up and down key does not focus the checkbox. I have to click the checkbox in order to focus it. I have searched Google for solutions but there weren't clean solutions. Am I wanting too much?

I just want the behavour of CheckedListBox...

I worked around (1) by handling the PreviewMouseDown event of the checkbox and manually selecting the item. It does not seem to be clean.

7
задан Damn Vegetables 5 May 2011 в 17:16
поделиться