targettype

Setting a style's TargetType property to a base class

自闭症网瘾萝莉.ら 提交于 2019-11-27 04:44:16
I was just poking around a bit in WPF and wanted all elements on my Window to share the same margin. I found that all Controls that are capable of having a margin derive from FrameworkElement so I tried the following: <Window.Resources> <Style TargetType="{x:Type FrameworkElement}"> <Setter Property="Margin" Value="10" /> </Style> </Window.Resources> And, this doesn't work. I can apply this to all Buttons, but not to all Elements that derive from Button. Am I missing something or is this simply not possible? Am I the only one feeling like using CSS for WPF would have been a good idea? Nicholas

Difference between TargetType=“controlType” and TargetType=“{x:Type controlType}”

ぐ巨炮叔叔 提交于 2019-11-26 16:52:38
问题 In WPF you can set the TargetType to either the name of the type or you can set it to {x:Type nameOfType} . Does anyone know what the difference is? 回答1: Nothing. Since the property type is Type , the XAML parser knows to try and convert whatever you supply to a Type . In other scenarios, the property type might be less specific (eg. Object ), and that's where you need the markup extension, otherwise the XAML parser will just interpret your value as a String . 回答2: Sorry for poking such an

Setting a style&#39;s TargetType property to a base class

北城余情 提交于 2019-11-26 11:20:23
问题 I was just poking around a bit in WPF and wanted all elements on my Window to share the same margin. I found that all Controls that are capable of having a margin derive from FrameworkElement so I tried the following: <Window.Resources> <Style TargetType=\"{x:Type FrameworkElement}\"> <Setter Property=\"Margin\" Value=\"10\" /> </Style> </Window.Resources> And, this doesn\'t work. I can apply this to all Buttons, but not to all Elements that derive from Button. Am I missing something or is