将代码添加到 WPF 中的样式
我有几个项目,例如,我希望文本框始终以相同的方式运行。对于诸如背景和长度之类的一切,都可以,但我还想添加基本事件处理程序(在本例中为“获得焦点”事件)。
这可能吗?如果可能的话怎么办?
谢谢。
编辑:这是一个示例:
<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>
我所有的样式都在资源字典中
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).
Is this possible and if so how ?
Thanks.
Edit : here is an example :
<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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不在项目中使用常见的验证方法而不是创建一些奇怪的东西?
尝试阅读此WPF 数据绑定和验证规则最佳实践
Why not to use common approach for validation in your project instead of creating something weird?
Try to read this WPF Data Binding and Validation Rules Best Practices