WPF:创建四角文本框

本文关键字:四角 文本 创建 WPF | 更新日期: 2023-09-27 18:04:56

在WPF中,我试图在每个角创建一个具有四个标签的按钮。它看起来像一个骰子(骰子?),在角落里有文字而不是点。

这段代码不起作用:

<Button HorizontalAlignment="Stretch" Background="Red" Height="100" >
    <Grid ShowGridLines="True">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition/>                               
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition/>                                                
        </Grid.ColumnDefinitions>
        <Label Grid.Row="0" Grid.Column="0" Content="TopLeft"/>
        <Label Grid.Row="0" Grid.Column="1" Content="TopRight" HorizontalContentAlignment="Right" VerticalContentAlignment="Bottom" HorizontalAlignment="Right" VerticalAlignment="Bottom" />
        <Label Grid.Row="1" Grid.Column="0" Content="BottomLeft"/>
        <Label Grid.Row="1" Grid.Column="1" Content="BottomRight" HorizontalContentAlignment="Right" VerticalContentAlignment="Bottom" HorizontalAlignment="Right" VerticalAlignment="Bottom" />
</Grid>
</Button>

它将文本挤到网格的中心,而不是将其移动到角落。看起来网格并没有占据按钮的所有空间。

感谢任何帮助。谢谢你。

WPF:创建四角文本框

设置按钮拉伸的VerticalContentAlignmentHorizontalContentAlignment

<Button HorizontalAlignment="Stretch" Background="Red" Height="100" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
    <Grid ShowGridLines="True" VerticalAlignment="Stretch" >
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Label Grid.Row="0" Grid.Column="0" Content="TopLeft"/>
        <Label Grid.Row="0" Grid.Column="1" Content="TopRight" HorizontalContentAlignment="Right" VerticalContentAlignment="Bottom" HorizontalAlignment="Right" VerticalAlignment="Bottom" />
        <Label Grid.Row="1" Grid.Column="0" Content="BottomLeft" VerticalContentAlignment="Bottom" />
        <Label Grid.Row="1" Grid.Column="1" Content="BottomRight" HorizontalContentAlignment="Right" VerticalContentAlignment="Bottom" HorizontalAlignment="Right" VerticalAlignment="Bottom" />
    </Grid>
</Button>