Шаблон выбранного элемента SurfaceListBox

Я использую Microsoft Surface SDK, и у меня возникают проблемы со стилем выбранного элемента.

Пока у меня есть:

<s:SurfaceListBox Name="listy" Background="Transparent"
                    FontSize="50" Foreground="White" BorderBrush="White"
                    HorizontalContentAlignment="Center"
                    Margin="5,5,5,100" SelectionMode="Single">
    <s:SurfaceListBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding}" Foreground="White" />
        </DataTemplate>
    </s:SurfaceListBox.ItemTemplate>
    <s:SurfaceListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                        <ContentPresenter HorizontalAlignment="Center" />
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Background" Value="Grey" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </s:SurfaceListBox.ItemContainerStyle>
</s:SurfaceListBox>

Но это не удается, и в Интернете вообще нет руководств по этому поводу - я искал часы.

Спасибо за любую помощь!


person tcables    schedule 24.02.2011    source источник
comment
Ищите руководства по стилизации обычных элементов управления списком. Тот же код будет работать на Surface.   -  person Robert Levy    schedule 25.02.2011


Ответы (1)


Я думаю, проблема в том, что ничто не использует этот фон. Вы можете обернуть ContentPresenter в Border и указать его в триггере.

<ControlTemplate TargetType="{x:Type s:SurfaceListBoxItem}">
    <Border x:Name="Border">
        <ContentPresenter HorizontalAlignment="Center" />
    </Border>
    <ControlTemplate.Triggers>
        <Trigger Property="IsSelected" Value="True">
            <Setter TargetName="Border" Property="Background" Value="Gray"/>
        </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>
person Fredrik Hedblad    schedule 24.02.2011