ZuT*_*uTa 67 .net silverlight wpf xaml
如何在Silverlight中基于默认样式创建样式?
例如,在WPF中我们使它像:
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Margin" Value="2" />
<Setter Property="Padding" Value="2" />
</Style>
Run Code Online (Sandbox Code Playgroud)
Chr*_* W. 26
几乎相同的.只需减去x:Type更明确的命名.
<Style TargetType="TextBox" BasedOn="{StaticResource DefaultTextBoxStyle}">
Run Code Online (Sandbox Code Playgroud)
更多信息请参见文档.PS,如果您需要默认模板,例如TextBox通常可以在CoreStyles.xaml中找到
如果您在第一次阅读答案时感到困惑,请按照评论中的要求添加附件;
" 你需要一个基本风格,这很容易做,因为你打算在一个应用程序主题中执行它,比如Silverlight默认提供(wpf/uwp等不会有这些),它们会创建像ToolkitStyles.xaml这样的文件,SDKStyles.xaml,CoreStyles.xaml等......答案中的静态资源名称来自于最初回答的那一年中针对Silverlight版本的问题."
AJ *_*son 21
要基于默认样式创建样式,您需要创建命名样式,然后根据命名样式创建默认样式(http://weblogs.asp.net/lduveau/silverlight-how-to-inherit-from - 隐式式)
<Style x:Key="DefaultCustomControlStyle" TargetType="local:CustomControl">
<Setter Property="Padding" Value="2" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:CustomControl">
<ContentPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="local:CustomControl" BasedOn="{StaticResource DefaultCustomControlStyle}" />
Run Code Online (Sandbox Code Playgroud)
小智 11
I would recommand to have a look at : https://justinmchase.com/2009/05/29/derived-styles-based-on-unnamed-default-styles/ It would go like this for you :
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
47512 次 |
| 最近记录: |