能帮忙看下EventTrigger为什么没有触发么?

windxx 2012-08-16 01:26:55
我定义了以下简单CustomerControl:

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:StoryboardTest">

<Style TargetType="{x:Type local:CustomControl1}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:CustomControl1}">
<Viewbox>
<Grid Background="LightBlue" x:Name="theGrid">
<Rectangle x:Name="faceRect" Width="50" Height="50" >
<Rectangle.RenderTransform>
<ScaleTransform CenterX="25" CenterY="25" ScaleX="1" ScaleY="1"/>
</Rectangle.RenderTransform>
</Rectangle>
</Grid>
</Viewbox>

<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="Rectangle.MouseEnter" SourceName="faceRect">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="faceRect"
Storyboard.TargetProperty="Width"
To="100"/>
<DoubleAnimation Storyboard.TargetName="faceRect"
Storyboard.TargetProperty="Height"
To="100"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="Rectangle.MouseLeave" SourceName="faceRect">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="faceRect"
Storyboard.TargetProperty="Width"
To="50"/>
<DoubleAnimation Storyboard.TargetName="faceRect"
Storyboard.TargetProperty="Height"
To="50"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

想实现鼠标进入或出控件中的Rectangle时候,分别播放动画,但是,运行却没有反应,如果将EventTrigger的RoutedEvent更改为:<EventTrigger RoutedEvent="Grid.MouseEnter">以及<EventTrigger RoutedEvent="Grid.MouseLeave">则可以触发,请问这是为什么?多谢
...全文
436 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
windxx 2012-08-17
  • 打赏
  • 举报
回复
的确是因为没有Fill的关系,非常感谢
assky124 2012-08-16
  • 打赏
  • 举报
回复
有个Fill属性吧,反正就是背景色,如果全透明的话,就捕获不到鼠标的。

你试试,我也没测试过
windxx 2012-08-16
  • 打赏
  • 举报
回复
assky124:另外之前那个问题不小心结了没给您分,真抱歉,我给了你一封私信,有空帮忙看下,这个问题还需要大家帮忙啊,谢谢了
windxx 2012-08-16
  • 打赏
  • 举报
回复
呵呵,谢谢您的回复,这两天问的问题都无人理会,只有你帮忙回了,真感谢。
Rectangle好像没有Background属性吧?
assky124 2012-08-16
  • 打赏
  • 举报
回复
Rectangle 的Background 设置为 "#01000000" 试试
windxx 2012-08-16
  • 打赏
  • 举报
回复
没写全,改为:


<EventTrigger RoutedEvent="Grid.MouseEnter" SourceName="theGrid">

以及
<EventTrigger RoutedEvent="Grid.MouseLeave" SourceName="theGrid">

或者改为:
<EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="theGrid">

以及
<EventTrigger RoutedEvent="Mouse.MouseLeave" SourceName="theGrid">

均可,只要是SourceName="faceRect"就不行,事件就好像触发不了了,请帮忙看下,非常感谢您的帮助!

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧