0

前の質問に関連して、青色の背景を無効にする次のコードがあります。

<ListBox Background="Transparent" BorderBrush="Transparent">
    <ListBox.Style>
        <Style>
            <Style.Resources>
                <!-- Background of selected item when focussed -->
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
                <!-- Background of selected item when not focussed -->
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
            </Style.Resources>
        </Style>
    </ListBox.Style>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Border Margin="5" BorderThickness="2" BorderBrush="LightGray" CornerRadius="5">
                <Expander IsExpanded="True" Background="#f7f7f7">
                    <!-- Content -->
                </Expander>
            </Border>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ListBox>

私が気付いたのは、コンテンツ内にあるコンボ ボックスなどのすべてのものも、透明な選択の同じスタイルを持っているということです。ListBoxItem のみを透過し、その内容を透過しないようにするには、どうすればよいですか?

4

2 に答える 2

1

次のように、DataTemplate でこれらのブラシを元の値に設定できます。

          <DataTemplate>
                <DataTemplate.Resources>
                    <!-- Background of selected item when focussed -->
                    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Blue" />
                    <!-- Background of selected item when not focussed -->
                    <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Blue" />
                </DataTemplate.Resources>
                <Border Margin="5" BorderThickness="2" BorderBrush="LightGray" CornerRadius="5">
                    <Expander IsExpanded="True" Background="#f7f7f7">
                        <!-- Content -->

                    </Expander>
                </Border>
            </DataTemplate>
于 2013-04-26T02:14:04.390 に答える