2
  1. 画像のアスペクト比に関係なく、テキストをボタンの一番下に固定したいと思います。
  2. ボタンの残りのスペースに合わせて画像を拡大したいのですが。

このxamlでは、残りのスペースに画像が表示されますが、テキストはボタンの一番下ではなく、画像のすぐ下に配置されます。DockPanel以外のものを使用する必要があるかもしれませんが、何を使用すればよいかわかりません。動作する別の方法がある場合は、テキストをラベルに含める必要はありません。

ありがとう

<Button Height="150" Width="150">
    <DockPanel LastChildFill="True">
        <Label HorizontalContentAlignment="Center" DockPanel.Dock="Bottom">foo</Label>
        <Image Source="bar.png" />
    </DockPanel>
</Button>
4

3 に答える 3

3

Button要素は、そのコンテンツがButton領域全体を自動的に埋めることを許可しません。これを行うには、Horizo​​ntalContentAlignmentプロパティとVerticalContentAlignmentプロパティの両方を「Stretch」に設定する必要があります。

<Button Height="150" Width="150"
        HorizontalContentAlignment="Stretch"
        VerticalContentAlignment="Stretch">
    <DockPanel LastChildFill="True">
        <Label HorizontalContentAlignment="Center" DockPanel.Dock="Bottom">foo</Label>
        <Image Source="bar.png" />
    </DockPanel>
</Button>
于 2012-06-05T15:32:56.980 に答える
2

ほとんどの場合、を親コンテナDockPanelに展開するように指示する必要があります。Height

<Button x:Name="button" Height="150" Width="150">
  <DockPanel LastChildFill="True" Height="{Binding Height, ElementName=button}">
    <Image DockPanel.Dock="Top" Source="bar.png" />
    <Label DockPanel.Dock="Bottom" HorizontalContentAlignment="Center" 
            VerticalAlignment="Bottom">foo</Label>
  </DockPanel>
</Button>
于 2012-06-05T15:26:41.053 に答える
1

簡単な実験をしました

多分これは役立ちますか?

<Grid>
   <Grid.RowDefinitions>
        <RowDefinition Height="64*"  />
         <RowDefinition Height="30"  />
   </Grid.RowDefinitions>
         <Image Source="bar.png" Stretch="UniformToFill"  Grid.Row="0" />
         <Label DockPanel.Dock="Bottom" Content="Foo" HorizontalAlignment="Center" Grid.Row="1" x:Name="Label1" VerticalAlignment="Bottom" ></Label>
</Grid>

行の高さを調整してみてください。

于 2012-06-05T14:49:55.577 に答える