我有一个按钮控件样式,我想更改任何数据绑定版本的填充,以针对需要 2 像素偏移的字形进行调整。我将使用 SimpleStyles.xaml 中的 SimpleButton 作为示例(...显示为简洁起见删除了触发器代码的位置):
<Style x:Key="SimpleButton" TargetType="{x:Type Button}" BasedOn="{x:Null}">
<Setter Property="FocusVisualStyle" Value="{DynamicResource SimpleButtonFocusVisual}"/>
<Setter Property="Background" Value="{DynamicResource NormalBrush}"/>
<Setter Property="BorderBrush" Value="{DynamicResource NormalBorderBrush}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<!-- We use Grid as a root because it is easy to add more elements to customize the button -->
<Grid x:Name="Grid">
<Border x:Name="Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}"/>
<!-- Content Presenter is where the text content etc is placed by the control. The bindings are useful so that the control can be parameterized without editing the template -->
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" RecognizesAccessKey="True"/>
</Grid>
...
</Setter.Value>
</Setter>
</Style>
我想要做的是在 Padding="{TemplateBinding Padding}" 的地方添加一些额外的边距。像 Padding="{TemplateBinding Padding} + 2,0,0,0" 这样的东西。
有 XAML 语法吗?如果没有,在代码中执行此操作时是否有最佳方法(装饰器?)?