在WPF中向样式添加代码 [英] Add code to a style in WPF

查看:45
本文介绍了在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中向样式添加代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆