2010-01-06 30 views
0

我有一個我的列表框項目的模板。它包含一個圖像按鈕。懸停時,按鈕會更改圖像。我遇到的問題是,當我懸停時,會在按鈕上添加一個奇怪的工件。這隻會發生,雖然它是在一個ListBoxItem。如果我把按鈕放在主畫布上,它可以正常工作。IsMouseOver在ListBoxItem按鈕上的奇怪問題

以下是在正常狀態下的圖像:

alt text

這裏是懸停狀態的圖像:請注意2條白線在頂部邊緣和右邊緣。

alt text

什麼是更奇怪的是,當你將鼠標移開,並將其恢復的圖像,神器停留:

alt text

這裏是我的按鈕的代碼。我試着用不同背景刷(包括按鈕,列表框項目等)打

<Style x:Key="RedXButton" TargetType="{x:Type Button}"> 
     <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/> 
     <Setter Property="Background" Value="Black"/> 
     <Setter Property="BorderBrush" Value="Transparent"/> 
     <Setter Property="BorderThickness" Value="0"/> 
     <Setter Property="Foreground" Value="Transparent"/> 
     <Setter Property="HorizontalContentAlignment" Value="Center"/> 
     <Setter Property="VerticalContentAlignment" Value="Center"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type Button}"> 
        <Image Width="19" Height="18"> 
          <Image.Style> 
           <Style TargetType="{x:Type Image}"> 
            <Setter Property="Source" Value="Views/Images/RedX.png"/> 
             <Style.Triggers> 
              <Trigger Property="IsMouseOver" Value="True"> 
               <Setter Property="Source" Value="Views/Images/RedXHover.png"/> 
              </Trigger> 
             </Style.Triggers> 
           </Style> 
          </Image.Style> 
         </Image> 
        <ControlTemplate.Triggers> 
         <Trigger Property="IsKeyboardFocused" Value="true"/> 
         <Trigger Property="ToggleButton.IsChecked" Value="true"/> 
        </ControlTemplate.Triggers> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
     <Setter Property="Width" Value="19"/> 
     <Setter Property="Height" Value="18"/> 
     <Setter Property="OpacityMask" Value="{x:Null}"/> 
    </Style> 

我的列表框項目模板:

<Canvas x:Name="LayoutRoot"> 
     <Image x:Name="image" Source="/Views/Images/FileGradient.png" Width="375" Height="43"/> 
     <Button x:Name="RedX" Style="{DynamicResource RedXButton}" Command="{Binding RemoveCommand}" Canvas.Left="11" Canvas.Top="13" Width="19" Height="18" /> 
    </Canvas> 

回答

0

它結束了對衝突的不同元件的多個樣式。我不確定實際的修復是什麼。我簡化了所有樣式並重新創建了一些控件,並且它消失了。不幸的是,除了這個之外,我不能再添加任何東西,因爲我不確定最終是否解決了問題。

0

只是一個想法 - 嘗試設置在SnapsToDevicePixels財產您的列表框項目模板設置爲「true」。也可能是值得把它放在按鈕樣式:

<Setter Property="SnapsToDevicePixels" Value="true"/>