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 回答
0

您将必须定位ListBoxItem并添加到ListBox Resources

<ListBox>
  <ListBox.Resources>
    <Style TargetType="{x:Type ListBoxItem}">
        <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.Resources>
</ListBox>
于 2013-04-25T21:35:54.863 回答