如何在Silverlight中基于默认样式创建样式?
例如,在WPF中,我们将其设置为:
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Margin" Value="2" />
<Setter Property="Padding" Value="2" />
</Style>
如何在Silverlight中基于默认样式创建样式?
例如,在WPF中,我们将其设置为:
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Margin" Value="2" />
<Setter Property="Padding" Value="2" />
</Style>
差不多一样.只需减go 命名更明确的x:Type
.
<Style TargetType="TextBox" BasedOn="{StaticResource DefaultTextBoxStyle}">
更多信息here in the docs.另外,如果你需要默认模板,比如文本框通常可以在CoreStyles中找到.xaml
如果您在第一次阅读答案时感到困惑,请按照 comments 中的要求进行补遗;
"you DO need a base style,这真的很容易做到,因为您打算在Silverlight这样的应用程序主题中这样做(WPF/UWP等不会有这些),默认情况下会创建ToolkitStyles.xaml、SDKStyles.xaml、CoreStyles.xaml等文件……这就是答案中的静态资源名称的来源,因为它针对的是最初回答此问题的年份的Silverlight版本."(WPF/UWP等不会提供这些内容),它创建了ToolkitStyles.xaml、SDKStyles.xaml、CoreStyles.xaml等文件.