在WPF中向样式添加代码

编程入门 行业动态 更新时间:2024-10-22 23:28:46
本文介绍了在WPF中向样式添加代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有几个项目,例如,我希望始终以相同方式表现的文本框。对于像背景这样的长篇大论,这很好,但是我也想添加基本事件处理程序(在这种情况下,是获得焦点事件)。

I have several projects in which I have for exemple, textboxes that I would like to behave the same way always. For evertyhing like background to lenght, it's fine, but I also would like to add base event handler (in this case, the got focus event).

谢谢。

编辑:这是一个示例:

<Style x:Key="BaseComboBox" TargetType="ComboBox"> <Setter Property="FontSize" Value="12"></Setter> <Setter Property="Foreground" Value="Black"></Setter> <Setter Property="FontFamily" Value="Arial"/> <Setter Property="HorizontalAlignment" Value="Stretch"/> <Setter Property="VerticalAlignment" Value="Center"/> <Setter Property="Height" Value="22"/> <Setter Property="Margin" Value="5,0,5,0"/> <Setter Property="IsEditable" Value="True" /> <Add LostFocus Event that will validate the selection here...> </Style>

我所有的样式都在资源词典中

All my styles are in Resources Dictionaries

推荐答案

<Style x:Key="MyStyle"> <EventSetter Event="Control.GotFocus" Handler="Control_GotFocus"></EventSetter> </Style>

更多推荐

在WPF中向样式添加代码

本文发布于:2023-11-12 03:50:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580430.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:样式   中向   代码   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!