将默认样式应用于控件,而不在xaml中包括资源字典. [英] Applying a default style to a control without including resource dictionary in the xaml.

查看:72
本文介绍了将默认样式应用于控件,而不在xaml中包括资源字典.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.假设我有一种样式,需要将其应用于应用程序中特定类型的所有控件.我希望即使对于使用代码创建的控件也是如此.但是由于它们是用代码创建的,所以我不能在xaml中包含该样式.实际上 我正在winforms应用程序中创建它们.

Hello. Let's say I have a style and I need to apply it to all controls of a particular type inside application. I want that happen even for controls that created in code as well. But since they are created in code I can't include that style in xaml. Actually I'm creating them in winforms app. How can it be achieved?

推荐答案

不确定代码创建的控件,但是如果您不给Style赋予Key,它将应用于该控件中命名类型的每个控件.样式的TargetType.
Not sure about code created controls but if you give no Key to a Style it will apply to every control of the type named in the TargetType of the style.


这篇关于将默认样式应用于控件,而不在xaml中包括资源字典.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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