<Style x:Key="TestButton" TargetType="{x:Type Button}">
<Setter Property="Foreground" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Border Background="{TemplateBinding Background}" CornerRadius="5" BorderThickness="10" BorderBrush="{TemplateBinding BorderBrush}"/>
<StackPanel VerticalAlignment="Center">
<TextBlock HorizontalAlignment="Center" FontSize="50">line01</TextBlock>
<TextBlock HorizontalAlignment="Center" FontSize="80">line02</TextBlock>
</StackPanel>
<ContentPresenter/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="Black"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我想重用此模板。
模板需要两个可变值。
我只了解到{TemplateBinding something}
如何扩展值?
答案 0 :(得分:0)
您需要使用C#中的Dependency Property创建自定义控件。
DependencyProperty.Register("My_Property_Name_1", typeof(String), typeof(Custom_Control));
DependencyProperty.Register("My_Property_Name_2", typeof(String), typeof(Custom_Control));
类似的问题已经回答了here。