0

次のようなサーフェスリストボックスがあります

<s:SurfaceListBox x:Name="viewList" Height="200" Width="Auto" SelectedIndex="0"
                ItemsSource="{Binding Source={StaticResource views}, XPath=Views/View}"
                DisplayMemberPath="@Title"                    
                SelectionChanged="viewList_SelectionChanged" Grid.Row="2" VerticalAlignment="Bottom" HorizontalContentAlignment="Stretch" ScrollViewer.VerticalScrollBarVisibility="Disabled">
        <s:SurfaceListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch"/>
            </ItemsPanelTemplate>
        </s:SurfaceListBox.ItemsPanel>
    </s:SurfaceListBox>

次のように、App.xaml ファイルの項目のスタイルを設定しました。

<Style TargetType="{x:Type s:SurfaceListBoxItem}">

        <Style.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" 
                     Color="#0071bc"/>
        </Style.Resources>
        <Setter Property="Height" Value="200"></Setter>
        <Setter Property="Width" Value="480"></Setter>
        <Setter Property="BorderThickness" Value="0,0,0,0"></Setter>
        <Setter Property="Padding" Value="20,20,0,20"></Setter>
        <Setter Property="Margin" Value="0"></Setter>
        <Setter Property="Foreground" Value="White"></Setter>
        <Setter Property="BorderBrush" Value="White"></Setter>
        <Setter Property="FontSize" Value="57"></Setter>
        <Setter Property="FontFamily" Value="TitilliumText22L"></Setter>
        <Setter Property="FontWeight" Value="Bold"></Setter>
        <Setter Property="TextBlock.TextAlignment" Value="Left"></Setter>
        <Setter Property="TextBlock.HorizontalAlignment" Value="Stretch"></Setter>
        <Setter Property="Background">
            <Setter.Value>
                <LinearGradientBrush>
                    <GradientStop Color="#3c3c3c" Offset="0"></GradientStop>
                    <GradientStop Color="#383838" Offset="0.6"></GradientStop>
                    <GradientStop Color="#6d6e6e" Offset="1"></GradientStop>
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="Foreground" Value="White"></Setter>
                <Setter Property="BorderBrush" Value="#0071bc"></Setter>
                <Setter Property="Background" Value="#0071bc"></Setter>
            </Trigger>
        </Style.Triggers>
    </Style>

私の問題は、スタイリングで説明されている色とは対照的に、選択したアイテムの背景色が白のままであることです。任意のポインタをいただければ幸いです

4

2 に答える 2

2

あなたがまだあなたの答えを見つけたかどうかはわかりませんが、私は同じ問題に遭遇しました。自分のスタイルでサーフェスカラーリソースを設定してみてください。表面の色のリストはここにあります:http://msdn.microsoft.com/en-us/library/microsoft.surface.presentation.surfacecolors_properties.aspx

SurfaceColorsの名前空間をインポートしてください

xmlns:sc="clr-namespace:Microsoft.Surface.Presentation;assembly=Microsoft.Surface.Presentation"

次に、SurfaceListBoxスタイルのサーフェスカラーを更新します。

<s:SurfaceListBox>
     <s:SurfaceListBox.ItemContainerStyle>
         <Style TargetType="s:SurfaceListBoxItem">
              <Style.Resources>
                 <SolidColorBrush x:Key="{x:Static sc:SurfaceColors.ListBoxItemSelectionBackgroundBrushKey }" Color="#FFA2CD65"/>
              </Style.Resources>
          </Style>
     </s:SurfaceListBox.ItemContainerStyle>
</s:SurfaceListBox>
于 2012-06-27T15:11:12.550 に答える
0

独自のリストボックスを作成しようとしているようです。通常、これを行う必要はありませんが、必要と思われる場合は、GetContainerForItemOverrideメソッドをオーバーライドするようにしてください。

    protected override DependencyObject GetContainerForItemOverride()
    {
        return new SurfaceListBoxItem();
    }
于 2012-06-17T05:26:05.753 に答える