0

I wrote my own checkbox ContentControl for better design control.

What the scenario looks like:

I got a Listbox with custom templated list items, which, in turn, have a text item and my custom checkbox.

Wanted behaviour:

  • clicking on the list item changes page to a detailed view of that item.
  • clicking the checkbox only toggles the checkmark on it and does not trigger the page change.

Actual behaviour:

You may guess, when clicking on my checkbox, the page change event is still fired.

How I implemented that:

My checkbox has a Grid, which holds a Rectangle and an Icon. I bound a Tap event to the Grid, to toggle the IsChecked status. (Grid objects don't have a click event).

Is it because I'm not using a click event? If so, which interface does my ContentControl have to implement for it? Or how does the default Checkbox (Button?) control manage that?

Thanks for your help.

4

1 回答 1

1

我编写了自己的复选框 ContentControl 以获得更好的设计控制

如果你觉得你真的必须创建你自己的 CheckBox,你的控件应该扩展 ToggleButton。这会给你你想要的行为。如果标准复选框不适合您,我会感到非常惊讶。您可以更改复选框的样式以做任何您想做的事情,更改为您想要的任何内容。我正在做你想做的事情,而且效果很好。ItemTemplate我在a中使用了一个复选框ListBox。我已将复选框设置为与常规复选框不同的外观。这是我的 ListBox 的示例

<ListBox ItemsSource="{Binding Items}"
         SelectionChanged="Stations_SelectionChanged"
         toolkit:TiltEffect.IsTiltEnabled="True"
         SelectionMode="Single">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Grid Margin="0,0,0,17">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="48"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
                <CheckBox IsChecked="{Binding YesOrNo, Mode=TwoWay}" Width="48"
                          Style="{StaticResource MinimalCheckBoxStyle}"/>
                <TextBlock Text="{Binding Name}" VerticalAlignment="Center"
                   Style="{StaticResource PhoneTextExtraLargeStyle}"
                           Grid.Column="1"/>
                <TextBlock Text="{Binding OtherProperty}"
                           Style="{StaticResource PhoneTextSubtleStyle}"
                           Grid.Column="1" Grid.Row="1"/>
            </Grid>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
于 2012-06-25T03:25:20.440 回答