2015-06-07 75 views
1

这是我ListView项后,我作出一些改动:如何改变ListView的边界时,鼠标上并选择

<ListView.ItemContainerStyle> 
     <Style TargetType="{x:Type ListViewItem}"> 
      <Setter Property="Background" Value="Transparent" /> 
      <Setter Property="Foreground" Value="White" /> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="{x:Type ListViewItem}"> 
         <Border 
       BorderBrush="White" 
       BorderThickness="0" 
       Background="{TemplateBinding Background}"> 
          <GridViewRowPresenter HorizontalAlignment="Stretch" 
           VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
           Width="Auto" Margin="0" Content="{TemplateBinding Content}"/> 
         </Border> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 
    </ListView.ItemContainerStyle> 

Background colorTransparentForeground colorWhite

虽然MouseOverListView item selected什么都没有改变,这意味着当期的观点没有改变,我想在MouseOverBorderColor更改为White,虽然Selected我想改变BorderColor蓝色。

编辑:

尝试后的代码示例这2条线:

<Setter Property="Background" TargetName="Bd" Value="{StaticResource Item.SelectedActive.Background}"/> 
<Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource Item.SelectedActive.Border}"/ 

收到错误的资源Item.SelectedActive.Bachground无法解析和资源Item.SelectedActive.Border不能解决。

回答

0

更改鼠标悬停和选择的颜色有陶添加触发器的一个ListViewItem:

<Style TargetType="{x:Type ListViewItem}"> 
      <Setter Property="Foreground" Value="White"/> 
      <Setter Property="SnapsToDevicePixels" Value="True"/> 
      <Setter Property="Padding" Value="4,1"/> 
      <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> 
      <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> 
      <Setter Property="Background" Value="Transparent"/> 
      <Setter Property="BorderBrush" Value="Transparent"/> 
      <Setter Property="BorderThickness" Value="1"/> 
      <Setter Property="FocusVisualStyle" Value="{x:Null}"/> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="{x:Type ListViewItem}"> 
         <Border 
      BorderBrush="White" 
      BorderThickness="0" 
      Background="{TemplateBinding Background}"> 
         <GridViewRowPresenter HorizontalAlignment="Stretch" 
          VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
          Width="Auto" Margin="0" Content="{TemplateBinding Content}"/> 
        </Border> 
         <ControlTemplate.Triggers> 
          <MultiTrigger> 
           <MultiTrigger.Conditions> 
            <Condition Property="IsMouseOver" Value="True"/> 
           </MultiTrigger.Conditions> 
           <Setter Property="Background" TargetName="Bd" Value="Transparent"/> 
           <Setter Property="BorderBrush" TargetName="Bd" Value="White"/> 
          </MultiTrigger> 
          <MultiTrigger> 
           <MultiTrigger.Conditions> 
            <Condition Property="Selector.IsSelectionActive" Value="False"/> 
            <Condition Property="IsSelected" Value="True"/> 
           </MultiTrigger.Conditions> 
           <Setter Property="Background" TargetName="Bd" Value="Transparent"/> 
           <Setter Property="BorderBrush" TargetName="Bd" Value="Blue"/> 
          </MultiTrigger> 
          <MultiTrigger> 
           <MultiTrigger.Conditions> 
            <Condition Property="Selector.IsSelectionActive" Value="True"/> 
            <Condition Property="IsSelected" Value="True"/> 
           </MultiTrigger.Conditions> 
           <Setter Property="Background" TargetName="Bd" Value="Transparent"/> 
           <Setter Property="BorderBrush" TargetName="Bd" Value="Blue"/> 
          </MultiTrigger> 
          <Trigger Property="IsEnabled" Value="False"> 
           <Setter Property="TextElement.Foreground" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> 
          </Trigger> 
         </ControlTemplate.Triggers> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 
+0

请参阅我的更新后,尝试你的代码 –

+0

我修改和更新我的代码。请现在尝试它的工作确定 – ReeganLourduraj

+0

现在收到的资源FocusVisual无法解析该行Setter Property =“FocusVisualStyle”Value =“{StaticResource FocusVisual}”/> - 这是什么意思? –