2011-02-24 68 views
2

我正在使用Microsoft Surface SDK,並且遇到樣式選定項目的麻煩。SurfaceListBox所選項目模板

到目前爲止,我有:

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

但是失敗了,有沒有教程這在所有在互聯網上 - 我搜索小時。

感謝您的幫助!

+1

查找教程造型的正常列表框控件。相同的代碼將在Surface上運行。 – 2011-02-25 15:05:54

回答

0

我認爲問題在於沒有使用該背景。你可以在一個Border包裹ContentPresenter和目標它在觸發

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