2013-05-16 15 views
11

我有一個textblock,當前有一個觸發器,當鼠標進入時設置前景色,當它離開時返回默認值。我的問題是,我也想將鼠標指針改變我目前有以下如何編寫WPF觸發器來改變文本塊懸停上的光標

<Style TargetType="TextBlock" x:Key="FlatStyleButton"> 
     <Setter Property="Foreground" Value="White"/> 
     <Setter Property="Background" Value="#FF333333" /> 
     <Style.Triggers> 
      <EventTrigger RoutedEvent="UIElement.MouseEnter"> 
       <BeginStoryboard> 
        <Storyboard> 
         <ColorAnimation Duration="0:0:0.3" Storyboard.TargetProperty="Foreground.Color" To="CornflowerBlue" /> 
        </Storyboard> 
       </BeginStoryboard> 
      </EventTrigger> 
      <EventTrigger RoutedEvent="UIElement.MouseLeave"> 
       <BeginStoryboard> 
        <Storyboard> 
         <ColorAnimation Duration="0:0:0.3" Storyboard.TargetProperty="Foreground.Color" To="White" /> 
        </Storyboard> 
       </BeginStoryboard> 
      </EventTrigger> 
     </Style.Triggers> 
    </Style> 

我曾嘗試加入<Setter Property="Cursor" Value="Hand"></Setter>到各個地方,但它似乎從來沒有工作

+2

有一個觸發器來做到這一點,在http://stackoverflow.com/questions/1132971/wpf-trigger-to-change-cursor – 2013-05-16 10:33:07

+0

這也可以幫助你http://www.infragistics.com/community/forums/t/62255.aspx – 2013-05-16 10:34:21

+0

我已經嘗試過這樣的東西,它沒有工作 – John

回答

31

對不起球員正確的高中男生在我的部分錯誤恐懼,我正在嘗試會工作,但我修改了錯誤的資源文件。因此,如果其他人是intrested答案是:

<Style TargetType="TextBlock" x:Key="FlatStyleButton"> 
     <Setter Property="Foreground" Value="White"/> 
     <Setter Property="Background" Value="#FF333333" /> 
     <Style.Triggers> 
      <Trigger Property="IsMouseOver" Value="True"> 
       <Setter Property="Cursor" Value="Hand" /> 
      </Trigger> 
      <EventTrigger RoutedEvent="UIElement.MouseEnter"> 
       <BeginStoryboard> 
        <Storyboard> 
         <ColorAnimation Duration="0:0:0.3" Storyboard.TargetProperty="Foreground.Color" To="CornflowerBlue" /> 
        </Storyboard> 
       </BeginStoryboard> 
      </EventTrigger> 
      <EventTrigger RoutedEvent="UIElement.MouseLeave"> 
       <BeginStoryboard> 
        <Storyboard> 
         <ColorAnimation Duration="0:0:0.3" Storyboard.TargetProperty="Foreground.Color" To="White" /> 
        </Storyboard> 
       </BeginStoryboard> 
      </EventTrigger> 
     </Style.Triggers> 
    </Style> 
相關問題