wpf icon button样式(类似windows桌面图标)

1:icon button样式

<Style x:Key="IconButton" TargetType="{x:Type Button}">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type Button}">
        <Grid Background="{TemplateBinding Background}">
          <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition />
          </Grid.RowDefinitions>
          <Image Width="90" Height="90" Source="/images/test.png" Grid.Row="0"></Image>
          <ContentPresenter Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center"/>
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
  <Setter Property="Background" Value="{x:Null}"/>
  <Setter Property="Foreground" Value="#000000"/>
  <Style.Triggers>
    <Trigger Property="IsMouseOver" Value="True">
      <Setter Property="Background" Value="#dedede"/>
    </Trigger>
  </Style.Triggers>
</Style>

2:使用icon button样式

<Button Style="{StaticResource IconButton}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="120" Height="120">test</Button>

posted @ 2017-07-19 14:27  by-lhc  阅读(632)  评论(0)    收藏  举报