2016-03-27 50 views

回答

0

我使用了邊框,因爲如果我沒有記錯的話,這是它可以完成的唯一方法。

WINDOW.RESOURCES

<Style TargetType="{x:Type Border}"> 
    <Setter Property="Background" Value="White"/> 
    <Style.Triggers> 
     <Trigger Property="IsMouseOver" Value="True"> 
      <Setter Property="Background" Value="#FFE6E6E6"/> 
     </Trigger> 
    </Style.Triggers> 
</Style> 

GRID

<Border BorderBrush="#FF000000" BorderThickness="0,0,3,3" Grid.Row="0" Grid.Column="0"> 
    <Image Name="x0y0" Source="/Tictactoe;component/image/null-black.png"/> 
</Border> 

我希望我抓住了正確的東西給你。 :p

+0

不幸的是,當我懸停在上面的標籤上時,它不工作 –

+0

對不起。我認爲這可能是有用的。 – 2016-03-27 22:48:42

0

這是你在找什麼? `

<Grid> 
     <Rectangle x:Name="rect" Fill="{Binding ElementName=label, Path=Background}" /> 
     <TextBlock x:Name="label" Text="Hover over me" > 
      <TextBlock.Style> 
       <Style TargetType="TextBlock"> 
        <Setter Property="Height" Value="20" /> 
        <Setter Property="Width" Value="100" /> 
        <Setter Property="HorizontalAlignment" Value="Center" /> 
        <Setter Property="VerticalAlignment" Value="Center" /> 
        <Style.Triggers> 
         <Trigger Property="IsMouseOver" Value="True"> 
          <Setter Property="Background" Value="LightBlue" /> 
         </Trigger> 
        </Style.Triggers> 
       </Style> 
      </TextBlock.Style> 
     </TextBlock> 
    </Grid> 

`

+0

不,這不是我想要做的。我想我的問題還不夠清楚,我編輯了它。 –

0

我這是怎麼實現這種效果與我DataGridRow對象。也許它可以幫助。

<EventTrigger RoutedEvent="DataGridRow.DragEnter"> 
          <BeginStoryboard x:Name="DragEnterStoryboard"> 
           <Storyboard> 
            <ColorAnimation 
             Storyboard.TargetProperty="Background.Color" 
             To="{StaticResource PartEntityDragEnterBackgroundColor}" 
             Duration="0:0:0.25"/> 
            <ColorAnimation 
             Storyboard.TargetProperty="Foreground.Color" 
             To="{StaticResource PartEntityDragEnterForegroundColor}" 
             Duration="0:0:0.25"/> 
           </Storyboard> 
          </BeginStoryboard> 
         </EventTrigger> 
+0

這也沒有奏效。不知何故,當鼠標移動UIElement時,mouseenter事件不會被觸發。 –

+0

你確定你在使用DragEnter而不是MouseEnter嗎? – Jace

+0

我嘗試了兩種方法,但仍無法使用 –