簡體   English   中英

SurfaceListBox所選項目模板

[英]SurfaceListBox Selected Item Template

我正在使用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>

但這失敗了,並且互聯網上根本沒有關於此的教程-我搜索了幾個小時。

謝謝你的幫助!

我認為問題是沒有使用該背景的東西。 您可以將ContentPresenter包裹在Border並將其定位到Trigger中

<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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM