代码如下:

 1  <Style x:Key="ButtonStyle" TargetType="Button">
 2         <Setter Property="Template">
 3             <Setter.Value>
 4                 <ControlTemplate TargetType="Button">
 5                     <!--StackPanel是用来控制当Button长度变化时,位置的适应-->
 6                     <StackPanel x:Name="spPanel" Orientation="Horizontal" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" >
 7                         <Grid>
 8                             <Grid.Background>
 9                                 <ImageBrush Stretch="Fill" ImageSource="btn-n.png"/>
10                             </Grid.Background>
11                             <Grid.ColumnDefinitions>
12                                 <ColumnDefinition></ColumnDefinition>
13                                 <ColumnDefinition></ColumnDefinition>
14                             </Grid.ColumnDefinitions>
15                             <Border x:Name="logoImg" Width="60" Height="51">
16                                 <Border.Background>
17                                     <ImageBrush Stretch="None" ImageSource="btn-icon-up.png"/>
18                                 </Border.Background>
19                             </Border>
20                             <!--Viewbox是控制当文字的长度超出最长限制时,对文字进行缩小处理-->
21                             <Viewbox Grid.Column="1" MaxWidth="350">
22                                 <Label x:Name="lblContent" Padding="0,0,5,0" VerticalContentAlignment="Center" Content="{TemplateBinding Content}"/>
23                             </Viewbox>
24                         </Grid>
25                     </StackPanel>
26                 </ControlTemplate>
27             </Setter.Value>
28         </Setter>
29     </Style>
View Code

相关文章:

  • 2022-02-13
  • 2021-12-01
  • 2022-01-31
  • 2021-12-12
  • 2021-07-02
  • 2021-12-05
  • 2022-12-23
  • 2021-05-29
猜你喜欢
  • 2022-12-23
  • 2022-02-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-15
  • 2022-12-23
相关资源
相似解决方案