- 浏览: 389565 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (309)
- xaml C# wpf (0)
- scala java inner clas (1)
- Tools UML Eclipse UML2 (1)
- Timer .NET Framework (1)
- perl (6)
- python function paramter (1)
- Python Docstring (1)
- Python how to compare types (1)
- Python (8)
- java (5)
- C# (76)
- C# WPF (0)
- p4 (0)
- WPF (46)
- .net (6)
- xaml (1)
- javascript (40)
- windows (10)
- scala (4)
- winform (1)
- c++ (48)
- tools (12)
- cmd (1)
- os (0)
- CI (0)
- shell (0)
- C (2)
- haskell (49)
- functional (1)
- tool (1)
- gnu (1)
- linux (1)
- kaskell (0)
- svn (0)
- wcf (3)
- android (1)
最新评论
As dicsused in the subsection of Default (theme) style from the topic of Dependency Property Value Precedence we know that the theme style use the type as the key for controls; But when theme is applied to a given Element instanfe, themes lookup for the particule type is performed by checking the DefaultStyleKey;
from DefaultStyleKey, we know that it is a protected internal property, out of curious we want to find out what is the value of the DefaultStyleKey;
Below is the code that I used for the look up .
To reflection get a property
public static object ReflectionGetProperty(object obj, Type type , string propertyName, BindingFlags[] bindingFlags) { if (string.IsNullOrEmpty(propertyName)) throw new ArgumentException("propertyName"); if (bindingFlags == null) throw new ArgumentNullException("bindingFlags"); if (type == null) throw new ArgumentNullException("type"); if (bindingFlags.Length == 0) throw new ArgumentException("bindingFlags"); var binding = bindingFlags[0]; for (int i = 0; i < bindingFlags.Length; i++) { binding |= bindingFlags[i]; } var prop = type.GetProperty(propertyName, binding); if (prop != null) { return prop.GetValue(obj, null); } return null; }
To use the ReflectionGetProperty method to get the Value of "DefaultStyleKey"
public static object ReflectionGetDefaultStyle(FrameworkElement frameworkElement) { if (frameworkElement == null) throw new ArgumentNullException("frameworkElement"); object defaultStyleKey = ReflectionGetProperty(frameworkElement, typeof(FrameworkElement), "DefaultStyleKey", new BindingFlags[] { BindingFlags.NonPublic | BindingFlags.Instance }); if (defaultStyleKey != null) { var style = frameworkElement.TryFindResource(defaultStyleKey); return style; } return null; }
and suppose visual is an FrameworkElement, this is how you get Default Style.
FrameworkElement visual = ... var style = ReflectionGetDefaultStyle(visual);
If you inspect the value of DefaultStyleKey in the method, you will see that the value of the DefautlstyleKey as in the method ReflectionGetDefaultKey is
? defaultStyleKey {Name = "TextBlock" FullName = "System.Windows.Controls.TextBlock"} base {System.Type}: {Name = "TextBlock" FullName = "System.Windows.Controls.TextBlock"} Assembly: {PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35} ...
As you can see that it is just the Type of textBlock (our Visual is a TextBlock);
It does not have some pratical siginificance, but some explore that is interesting.
发表评论
-
wpf - example to enhance ComboBox for AutoComplete
2014-09-19 15:56 1939first let’s see an example ... -
WPF – Virtualization – VirutalizationStackPanel and ItemsPanelTemplate
2013-08-05 21:55 1361Topic: WPF – Virtualization – ... -
wpf - BehaviorBase and one use examples
2013-06-18 18:41 1279Behavior is something that we ... -
WPF - Setting foreground color of Entire window
2013-06-13 16:00 1880You might as well as I would s ... -
WPF - Enhanced TabControl - TabControlEx aka Prerendering TabControl
2013-06-13 13:12 5292As an opening word, let's che ... -
wpf - ControlTemplate and AddLogicChild/RemoveLogicalChild
2013-06-10 15:42 1144Recently I was trying to debug ... -
wpf - default implicit style
2013-05-10 10:24 770We know that if you left out ... -
wpf - Style setter on the attached property
2013-05-08 14:54 2820I believe that you are familia ... -
wpf - specify enum values in xaml
2013-05-08 11:31 3544Many a situation you find tha ... -
wpf - IG xamDataGrid bind to XmlDataProvider with Xml Island
2012-12-18 14:28 1253Sometimes you may bind to some ... -
wpf - translate winform button/mouse event to wpf events
2012-12-12 17:37 2128It is common that we sometimes ... -
wpf - Freezable and its meaning
2012-09-27 12:38 0This article is based on the di ... -
wpf - Customize the grid lines for original wpf Grid control
2012-09-27 12:01 1428The System.WIndows.Controls.Gri ... -
c# - Convert from System.Drawing.Image to System.WIndows.Media.ImageSource
2012-09-25 14:27 7369In Previous discussion, we have ... -
wpf - Get Effective DependencyProperty value on a DependencyObject
2012-08-28 19:05 1011As discussed in my previous pos ... -
wpf - Dependency Property Value Precedence
2012-08-28 18:56 835A dependency property to an Dep ... -
wpf - WPF TemplateBinding vs RelativeSource TemplatedParent
2012-08-28 14:20 3655This is a post that summarizes ... -
wpf - ICutomTypeDescriptor , PropertyDescriptor and its use in PropertyGrid
2012-08-28 14:04 3544The type ICustomTypeDe ... -
wpf - tips to convert UI controls in WPF/Silverlight/Winforms into a Bitmap
2012-08-27 17:44 935In previous discussion, we have ... -
wpf - input binding examples
2012-08-27 11:47 1178Input binding is the mechanism ...
相关推荐
bootstrap-wpf-style-master 样式代码 。。。。。。。。
gong-wpf-dragdrop, GongSolutions.WPF.DragDrop 库是WPF的拖动'n'拖放框架 简介GongSolutions.WPF.DragDrop 库是一个易于使用的拖拉'n'拖放框架。特性使用 MVVM: 拖放逻辑可以放在ViewModel中。 代码不需要放在in中...
学习在WPF当中如何使用Style定制TabControl的样式,包含TabControl的页面选项切换的简单动画效果。原始代码网上找的,我改了一些代码。
c#-的WPF---MVVM例子,大家共同学习
一个简单的WPF程序
C#开发WPF-Silverlight动画及游戏系列教程-深蓝色右手 C#开发WPF-Silverlight动画及游戏系列教程-深蓝色右手 C#开发WPF-Silverlight动画及游戏系列教程-深蓝色右手
Prism-Samples-Wpf-master06-10的VS2017版本实现,下载手动重新安装一下nuget包即可,方便大家学习
wpf--ListBox分组-排序 wpf--ListBox分组-排序
我最近打算学习WPF ,在寻找MVVM框架的时候发现了PRISM,在此之前还从一些博客上了解了其它的MVVM框架,比如浅谈WPF中的MVVM框架--MVVMFoundation 中提到的MVVMFoundation,再比如 ViewModel从未如此清爽 - 轻量级...
wpf-wcf-wf整合开发实例--有利于理解wpf-wcf-wf的整合
WPF收集程序
WPF的基本空间历程,使用.net core3.0.1版本
WPF--Effect特效 对Effect的进行使用的小例子
bootstrap样式的wpf,很好的例子,详细介绍了wpf使用bootstrap格式的样式的方法,有需要的可以下载
wpf-datagrid-access DB,可以更新数据到Access数据库
wpf-资源的使用-resource
wpf charts源码,D源码,图书:practical-wpf-charts-graphics-master
Wpf-图片放大缩小移动操作 Wpf-图片放大缩小移动操作
WPF-MVVM WPF MVVM模式开发的例子程序
C#开发WPF-Silverlight动画及游戏系列教程-深蓝色右手 C#开发WPF-Silverlight动画及游戏系列教程-深蓝色右手 C#开发WPF-Silverlight动画及游戏系列教程-深蓝色右手