样式中调用方法
前台:
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 }
作者:Ants_double
出处:https://www.cnblogs.com/ants_double/
本文版权归作者和博客园所有,欢迎转载。转载请在留言板处留言给我,且在文章标明原文链接,谢谢!
如果您觉得本篇博文对您有所收获,觉得我还算用心,请点击右下角的 [大拇指],谢谢!