2013-06-20 32 views
2

我簡化了我的問題與示例應用程序。所以我有一個用矩形表示一些對象的列表。在Windows 8的控制中刪除MouseOver狀態

但是我的問題是,如果我的應用程序打開Windows 8.當我將鼠標放在元素上時,我的矩形周圍會出現一個藍色的矩形。我嘗試了一些在互聯網上找到的解決方案,但都沒有工作。

我的代碼:

<Window x:Class="Test_application.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:Test_application" 
    Title="MainWindow" Height="350" Width="525"> 
<Grid Background="DarkGray"> 
    <ListBox Margin="10" x:Name="lbTest"> 
     <ListBox.Resources> 
      <DataTemplate DataType="{x:Type local:Segment}"> 
       <Rectangle Width="150" Height="10" Stroke="Gray" StrokeThickness="1.354" Margin="10"/> 
      </DataTemplate> 
     </ListBox.Resources> 
     <ListBox.ItemsPanel> 
      <ItemsPanelTemplate> 
       <Canvas /> 
      </ItemsPanelTemplate> 
     </ListBox.ItemsPanel> 
     <ListBox.ItemContainerStyle> 
      <Style TargetType="{x:Type ListBoxItem}"> 
       <Setter Property="Canvas.Left" Value="{Binding X}"/> 
       <Setter Property="Canvas.Top" Value="{Binding Y}"/> 
       <Setter Property="Margin" Value="0" /> 
       <Setter Property="Focusable" Value="False" /> 
       <Setter Property="Padding" Value="0" /> 
       <Setter Property="VerticalContentAlignment" Value="Stretch"/> 
       <Setter Property="HorizontalContentAlignment" Value="Stretch"/> 
       <Setter Property="Background" Value="{x:Null}" /> 
      </Style> 
     </ListBox.ItemContainerStyle> 
    </ListBox> 
</Grid> 

Application

回答

3

選擇和鼠標懸停顏色在Triggers定義在ControlTemplate爲ListBoxItem的,所以你需要自定義,如果你想對他們使用不同的(或不)顏色。根據你想如何原來的觸發功能多,你可以使原來的一個(Blend會爲你做這個)的副本,並修改它,還是用這樣簡單的東西:

 <ListBox.ItemContainerStyle> 
      <Style TargetType="{x:Type ListBoxItem}"> 
       <Setter Property="Canvas.Left" Value="{Binding X}"/> 
       <Setter Property="Canvas.Top" Value="{Binding Y}"/> 
       <Setter Property="Margin" Value="0" /> 
       <Setter Property="Focusable" Value="False" /> 
       <Setter Property="Padding" Value="0" /> 
       <Setter Property="VerticalContentAlignment" Value="Stretch"/> 
       <Setter Property="HorizontalContentAlignment" Value="Stretch"/> 
       <Setter Property="Background" Value="{x:Null}" /> 
       <Setter Property="Template"> 
        <Setter.Value> 
         <ControlTemplate TargetType="{x:Type ListBoxItem}"> 
          <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" 
            Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"> 
           <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> 
          </Border> 
         </ControlTemplate> 
        </Setter.Value> 
       </Setter> 
      </Style> 
     </ListBox.ItemContainerStyle> 

另外,您應該考慮你是否真的需要一個ListBox或者只能使用一個基地ItemsControl,它沒有你想擺脫的鼠標懸停行爲。這個決定應該基於你是否需要物品選擇,因爲這是ListBox增加的主要東西。

+0

天啊!是工作!! :) 我已經搜索今天的每一次,你找到解決方案。 謝謝。 –

0

默認亮點可以被覆蓋。

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

相反Orange顏色設置Transparent#00FFFFFF

編輯:

或者添加觸發器ItemContainerStyle

<Style TargetType="{x:Type ListBoxItem}"> 
    ... 
    <Style.Triggers> 
     <Trigger Property="IsMouseOver" Value="True"> 
      <Setter Property="Background" Value="Transparent" /> 
     </Trigger> 
    </Style.Triggers>  
    ... 
</Style> 
+0

謝謝你的回答,但我已經嘗試過了,但它不起作用。 :-s –