2015-06-07 29 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}」/> - 這是什麼意思? –