WPF,请问下这个路由事件怎么截取?

都放 2013-11-24 01:16:24

<Window.Resources>
<Style x:Key="aa" TargetType="Control">
<Setter Property="Background" Value="Wheat"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Control">
<Grid>
<TextBlock Text="汤姆" Background="Wheat"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="bb" TargetType="Control">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Control">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="张三" Background="Red"/>
<TextBlock Text="李四" Grid.Row="1" Background="Yellow"/>
<Control Style="{StaticResource aa}" Grid.Row="2" Background="Wheat"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<Control Style="{StaticResource bb}" MouseDown="Control_MouseDown"/>
</Grid>



private void Control_MouseDown(object sender, MouseButtonEventArgs e)
{

}




上面的样式中,要求鼠标点击到最下面一行那个Control时,也就是样式为aa的那个Control时,就将最下面那个Control的背景色变为黑色,请问,该怎么写?
...全文
103 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
都放 2013-11-24
  • 打赏
  • 举报
回复
引用 1 楼 qldsrx 的回复:
先给那个Control设个Name属性,然后事件里面判断sender参数的类型和Name属性是否符合,不符合的不处理。 if(sender is Control && ((Control)sender).Name=="")
MouseDown事件是在最外层的Control定义的,sender只能是最外层的Control啊
qldsrx 2013-11-24
  • 打赏
  • 举报
回复
先给那个Control设个Name属性,然后事件里面判断sender参数的类型和Name属性是否符合,不符合的不处理。 if(sender is Control && ((Control)sender).Name=="")

110,556

社区成员

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

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

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