lundi 13 mars 2017

How to style checkbox in multi-selection ListView in UWP

In UWP am using a multi-select ListView with an item template, like this:

    <ListView 
        ItemsSource="{x:Bind ItemsSource, Mode=OneWay}" 
        ItemTemplate="{x:Bind LineTemplate, Mode=OneWay}"
        SelectionMode="Multiple"
        >
    </ListView>

The problem is the style of the checkbox added by UWP. In the rest of my program I have my own style for checkboxes, and the one in the ListView doesn't match.

I don't see any way to style the checkbox, and I don't see any code lying around for the ListViewItemPresenter that is in the ListViewItem template.

Perhaps I could set IsMultiSelectCheckBoxEnabled="False" and then include my own CheckBox in the ListViewItem. I see how to add the CheckBox to the template in the ListViewItem style: I can put it right before the ListViewItemPresenter (using, say, a horizontal StackPanel). Then I can bind IsChecked="{TemplateBinding IsSelected}".

But if I do that, then I get the exception "ListViewItemPresenter can only be used as the first child in the template for a ListViewItem."

Is there a more or less simple way to do this?

--sjb

P.S. Obviously the ListViewItemPresenter is very special... I have the impression that it has a lot of optimization built into it, which one shouldn't just throw away.




Aucun commentaire:

Enregistrer un commentaire