2013-05-10 31 views
24

Tôi đang phát triển một ứng dụng WPF có nhật ký. Nhật ký được thiết kế với một listView. Các listviewitems hầu hết không thay đổi sự xuất hiện khi con chuột kết thúc hoặc mục được chọn. Rằng tôi đã giải quyết với phong cách này cho listview:WPF: Xóa hiệu ứng làm nổi bật khỏi ListViewItem

<Style x:Key="ItemContainerStyle1" TargetType="ListViewItem"> 
    <Setter Property="HorizontalContentAlignment" Value="Left"/> 
    <Style.Triggers> 
     <Trigger Property="IsMouseOver" Value="True"> 
      <Setter Property="Background" Value="Transparent" /> 
      <Setter Property="BorderThickness" Value="0" /> 
      <Setter Property="Focusable" Value="False" /> 
     </Trigger> 
    </Style.Triggers> 
</Style> 

Kiểu này đã khắc phục được sự cố của tôi nhưng đã nêu ra một vấn đề mới. Khi nền được đặt thành "Trong suốt", giờ đây tôi có thể thấy hiệu ứng di chuột/bóng này được hiển thị ở hình bên dưới, khi con chuột vượt qua mục xem danh sách.

enter image description here

Tôi đã cố gắng để giải quyết vấn đề với nỗ lực này, nhưng không có may mắn.

<Style TargetType="{x:Type ListViewItem}"> 
    <Style.Resources> 
     <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#00000000"/> 
     <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="#00000000"/> 
    </Style.Resources> 
</Style> 

Bất kỳ ai có ý tưởng cách xóa hiệu ứng di chuột gây phiền nhiễu này?

Cảm ơn trước

Trả lời

72

Tôi không biết nếu điều này là giải pháp duy nhất nhưng tôi đã làm điều đó như sau (bằng cách thiết lập Template tài sản của ListViewItem s):

<ListView.ItemContainerStyle> 
    <Style TargetType="{x:Type ListViewItem}"> 
     <Setter Property="Background" Value="Transparent" /> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type ListViewItem}"> 
        <Border 
         BorderBrush="Transparent" 
         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> 

CHỈNH SỬA:

Hoặc như Grant Winney gợi ý (tôi không tự mình kiểm tra):

<ListView.ItemContainerStyle> 
    <Style TargetType="{x:Type ListViewItem}"> 
     <Setter Property="Background" Value="Transparent" /> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type ListViewItem}"> 
        <ContentPresenter /> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
</ListView.ItemContainerStyle> 
+0

Thanks, điều này giải quyết vấn đề của tôi :) Được sử dụng hai ngày về vấn đề này! Tôi đã tự hỏi nếu bạn biết một cuốn sách hay một số trang chủ tốt để có được kiến ​​thức về phong cách? – mskydt86

+0

Chỉ [msdn] (http://msdn.microsoft.com/en-US/), http://wpftutorial.net/ và Google, xin lỗi .. có thể ai đó cũng có ý tưởng. – Matmarbon

+11

FWIW, nếu có ai đó gặp phải ai cũng định nghĩa 'ListView.ItemTemplate' của riêng mình, bạn sẽ cần phải thay thế mọi thứ bên trong các thẻ' ControlTemplate' bằng một '' duy nhất. –

2

Đối với tôi, làm việc tốt, như thế này:

<ListView.ItemContainerStyle> 
    <Style TargetType="ListViewItem"> 
    <Style.Triggers> 
     <Trigger Property="IsMouseOver" Value="True"> 
     <Setter Property="Background" Value="Transparent" /> 
     <Setter Property="BorderBrush" Value="Transparent" /> 
     <Setter Property="BorderThickness" Value="0" /> 
     </Trigger> 
    </Style.Triggers> 
    </Style> 
</ListView.ItemContainerStyle> 
2

Công việc này:

<Style TargetType="{x:Type ListViewItem}"> 
<Setter Property="Background" Value="Transparent" /> 
<Setter Property="BorderBrush" Value="Transparent"/> 
<Setter Property="VerticalContentAlignment" Value="Center"/> 
<Setter Property="Template"> 
    <Setter.Value> 
     <ControlTemplate TargetType="{x:Type ListViewItem}"> 
      <Grid Background="{TemplateBinding Background}"> 
       <Border Name="Selection" Visibility="Collapsed" /> 
       <!-- This is used when GridView is put inside the ListView --> 
       <GridViewRowPresenter Grid.RowSpan="2" 
             Margin="{TemplateBinding Padding}" 
             HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
             VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
             SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> 

      </Grid> 
     </ControlTemplate> 
    </Setter.Value> 
</Setter> 

1

Đã không phải là câu hỏi nhưng điều này làm việc cho tôi.

<Style TargetType="{x:Type ListBoxItem}"> 
      <Setter Property="Background" Value="Transparent" /> 
      <Setter Property="BorderBrush" Value="Transparent"/> 
      <Setter Property="VerticalContentAlignment" Value="Center"/> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="{x:Type ListBoxItem}"> 
         <Border Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"> 
           <ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" Margin="{TemplateBinding Padding}" /> 
          </Border> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 
0

Tôi gặp vấn đề tương tự, nhưng không có câu trả lời nào giúp tôi. Tìm kiếm trên web tôi tìm thấy giải pháp này và nó làm việc:

 <ListView.Resources> 
      <Style TargetType="{x:Type ListViewItem}"> 
       <Setter Property="Template"> 
        <Setter.Value> 
         <ControlTemplate TargetType="{x:Type ListViewItem}"> 
          <GridViewRowPresenter /> 
         </ControlTemplate> 
        </Setter.Value> 
       </Setter> 
      </Style> 
     </ListView.Resources> 
0

Hãy thử một trong này nó làm việc cho tôi.

     <Style TargetType="{x:Type ListBoxItem}"> 
          <Setter Property="Background" Value="Transparent" /> 
          <Setter Property="Template"> 
           <Setter.Value> 
            <ControlTemplate TargetType="{x:Type ListBoxItem}"> 
             <ContentPresenter HorizontalAlignment="Left" Margin="2,3,2,3" /> 
            </ControlTemplate> 
           </Setter.Value> 
          </Setter> 
         </Style> 
        </ListBox.ItemContainerStyle> 
Các vấn đề liên quan