右键单击时禁用ListBox突出显示

时间:2014-07-30 14:23:33

标签: c# wpf xaml listbox listboxitem

是否有人能够告诉我,以下源代码中的内容是什么?

(我正在尝试在右键单击时禁用我的listBox项目上的灰色突出显示)

<ListBox ItemsSource="{Binding TotoList}"
                         VerticalAlignment="Stretch"
                         VerticalContentAlignment="Top">
                    <ListBox.Style>
                        <Style TargetType="{x:Type ListBox}">
                            <Style.Resources>
                                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
                                                 Color="Transparent" />
                                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"
                                                 Color="Transparent" />
                            </Style.Resources>
                        </Style>
                    </ListBox.Style>
                    <ListBox.Template>
                        <ControlTemplate>
                            <Border  BorderBrush="DarkGray"
                                     BorderThickness="0">
                                <ItemsPresenter />
                            </Border>
                        </ControlTemplate>
                    </ListBox.Template>
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Border BorderBrush="Transparent"
                                    VerticalAlignment="Stretch"
                                    HorizontalAlignment="Stretch">
                                <Grid Width="120">
                                    <Label Content="{Binding Name}"
                                           HorizontalAlignment="Left"
                                           Margin="5,0,0,0"/>
                                </Grid>
                                <Border.Style>
                                    <Style TargetType="Border">
                                        <Style.Triggers>
                                            <Trigger Property="IsMouseOver"
                                                     Value="True">
                                                <Setter Property="Background"
                                                        Value="Transparent" />
                                            </Trigger>
                                        </Style.Triggers>
                                    </Style>
                        </Border.Style>
                        <Border.ContextMenu>
                             <ContextMenu>
                                  <MenuItem Header="Remove"
                                       Click="removeToto">
                                  </MenuItem>
                             </ContextMenu>
                        </Border.ContextMenu>
                   </Border>
             </DataTemplate>
       </ListBox.ItemTemplate>
  </ListBox>

当右键单击listBox项目以删除它时,该项目以灰色突出显示...

1 个答案:

答案 0 :(得分:0)

还将以下资源添加到ListBox资源中。以下键负责非活动选择画笔。

   <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}"
                                     Color="Transparent" />