2015-02-21 3 views
0

enter image description here Я не могу удалить границы в своем списке.Удалить границу выделения из ListView

Я искал многочисленные ссылки и до сих пор не могу удалить эту границу.

ListView:

<ListView x:Name="ConsoleView" Grid.Row="1" Grid.Column="0" ItemsSource="{Binding ConsoleLines}" 
       ClipToBounds="True" SelectedItem="{Binding ConsoleLine}" Margin="5" 
       Background="Black" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" 
       VerticalAlignment="Stretch" VerticalContentAlignment="Stretch" BorderThickness="0" Focusable="False"> 
     <ListView.ItemTemplate> 
      <DataTemplate> 
       <TextBox Style="{StaticResource TextBoxCommandStyle}" Text="{Binding Content, UpdateSourceTrigger=PropertyChanged}" 
         TextChanged="OnTextChanged" Loaded="OnCommandLineLoaded" BorderThickness="0" /> 
      </DataTemplate> 
     </ListView.ItemTemplate> 

     <ListView.ItemContainerStyle> 
      <Style TargetType="{x:Type ListViewItem}"> 
       <Setter Property="Background" Value="{x:Null}" /> 
       <Setter Property="BorderBrush" Value="{x:Null}" /> 
       <Setter Property="Focusable" Value="False" /> 
      </Style> 
     </ListView.ItemContainerStyle> 

     <ListView.Resources> 
      <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/> 
      <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/> 
     </ListView.Resources> 
    </ListView> 

Стиль:

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

    <Style TargetType="{x:Type ListViewItem}"> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type ListViewItem}"> 
        <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true"> 
         <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> 
        </Border> 
        <ControlTemplate.Triggers> 
         <Trigger Property="IsEnabled" Value="false"> 
          <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> 
         </Trigger> 
        </ControlTemplate.Triggers> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 


<Style x:Key="TextBoxCommandStyle" TargetType="TextBox"> 
      <Setter Property="HorizontalAlignment" Value="Stretch" /> 
      <Setter Property="HorizontalContentAlignment" Value="Stretch" /> 
      <Setter Property="Padding" Value="5" /> 
      <Setter Property="Margin" Value="5" /> 
      <Setter Property="Background" Value="Black" /> 
      <Setter Property="Foreground" Value="Cyan"/> 
      <Setter Property="FontSize" Value="20" /> 

      <Style.Triggers> 
       <DataTrigger Binding="{Binding Status}" Value="{x:Static viewModels:CommandStatus.Succeeded}"> 
        <DataTrigger.EnterActions> 
         <BeginStoryboard Storyboard="{StaticResource Storyboard1}"/> 
        </DataTrigger.EnterActions> 
       </DataTrigger> 
      </Style.Triggers> 
     </Style> 

ответ

1
  1. Ваш "Стиль" состоит из двух сеттеров для свойства "Шаблон". Зачем? Это ошибка?
  2. Ваш стиль ListViewItem из «Стиль» переопределяется в ListView.ItemContainerStyle. Для того, чтобы наследовать стиль, вы должны написать:

    Стиль TargetType = "{х: Тип ListViewItem}" BasedOn = "{StaticResource {х: Тип ListViewItem}}"

  3. Чтобы удалить цвет выбор:

{

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

}

Источник: Disable blue border for selected Listview item

+0

Я обновил XAML и все еще наблюдаю те же проблемы. Можете ли вы проверить мои изменения? –

+0

@ScottNimrod: Вы имеете в виду границу вокруг элемента управления ListView или выделенной границы вокруг ListViewItem? Я создал проект с вашим кодом и нет выделенной границы вокруг выбранных элементов. – VMaleev

+0

Это странно. Есть граница выделения и на сфокусированном listviewitem, а также когда я наводил указатель мыши на другие элементы. Я использую WPF. –

Смежные вопросы