博客园 首页 私信博主 显示目录 隐藏目录 管理 动画

样式中调用方法

前台:

 1  <Window.Resources>
 2         <Style TargetType="{x:Type TextBlock}" x:Key="ClickableTextBlockStyle">
 3             <EventSetter Event="MouseDown" Handler="TextBlock_MouseDown"/>
 4         </Style>
 5     </Window.Resources>
 6 
 7         <StackPanel>
 8       
 9             
10             <TextBlock Tag="1" Text="Customers" Style="{DynamicResource ResourceKey=ClickableTextBlockStyle}"/>
11         <TextBlock Tag="2" Text="Appointments"  Style="{DynamicResource ResourceKey=ClickableTextBlockStyle}"/>

后台:

1   private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
2         {
3             int id = Int32.Parse(((TextBlock)sender).Tag.ToString());
4             MessageBox.Show("you chose id "+id.ToString());
5         }

 

posted @ 2016-04-08 07:52  ants_double  阅读(144)  评论(0编辑  收藏  举报