我有一個按鈕控制樣式,並且我想要更改數據綁定版本針對需要2像素偏移量的字形調整的填充。我將使用的SimpleButton從SimpleStyles.xaml爲例(...表示,爲了簡明去除觸發代碼):您可以在數據綁定的WPF樣式中執行「數學」
<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>
我想要做的就是添加一些額外的保證金,其中填充=「{TemplateBinding填充}」。像Padding =「{TemplateBinding Padding} + 2,0,0,0」。
是否有XAML語法?如果沒有,在代碼(Decorator?)中做這件事情時是否有最佳方法?
你能提供的示例使用價值轉換器來做這個數學 - 它似乎更像是對我的濫用。 – 2008-11-30 04:25:58