在WPF中使Button内部的内容响应

时间:2018-09-26 12:05:00

标签: wpf xaml

我有垂直导航栏。导航的每个按钮都有其自己的图像和文本。目前,图像的静态高度设置为Height="50",文本具有默认值。当我调整窗口大小时,按钮会变得灵敏,但其中的内容保持不变。 现在是这样的: https://gyazo.com/48cff48437b66f462dccd23639dd59ac(GIF)

我的XAML代码:

  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="10*"/>
      <ColumnDefinition Width="2*"/>
    </Grid.ColumnDefinitions>
    <UniformGrid Background="DodgerBlue" Grid.Column="1" Columns="1">

      <Button BorderThickness="0" Background="DodgerBlue">
        <StackPanel>
          <Image Source="Icons/home-5-xxl.png" Height="50" Margin="0,0,0,10"/>
          <TextBlock HorizontalAlignment="Center" Foreground="White" FontWeight="Bold">Home</TextBlock>
        </StackPanel>
      </Button>

      <Button BorderThickness="0" Background="DodgerBlue">
        <StackPanel>
          <Image Source="Icons/search-3-xxl.png" Height="50" Margin="0,0,0,10"/>
          <TextBlock HorizontalAlignment="Center" Foreground="White" FontWeight="Bold">Search</TextBlock>
        </StackPanel>
      </Button>

      <Button BorderThickness="0" Background="DodgerBlue">
        <StackPanel>
          <Image Source="Icons/twitter-xxl.png" Height="50" Margin="0,0,0,10"/>
          <TextBlock HorizontalAlignment="Center" Foreground="White" FontWeight="Bold">Twitter</TextBlock>
        </StackPanel>
      </Button>

      <Button BorderThickness="0" Background="DodgerBlue">
        <StackPanel>
          <Image Source="Icons/chat-4-xxl.png" Height="50" Margin="0,0,0,10"/>
          <TextBlock HorizontalAlignment="Center" Foreground="White" FontWeight="Bold">Chat</TextBlock>
        </StackPanel>
      </Button>

    </UniformGrid>
  </Grid>

当XAML WPF中的按钮增长时,如何使按钮中的内容响应并增长?

1 个答案:

答案 0 :(得分:1)

使用Viewbox,如图here所示。

<Viewbox Stretch="Uniform">
   <Button ... />
</Viewbox>
相关问题