C#WinRT使控件大小填充其父级

时间:2014-08-19 20:34:45

标签: c# windows-runtime grid-layout

我是一名经验丰富的开发人员,但对C#和Windows Runtime不熟悉。我正在尝试创建一个可以动态调整大小的自定义UserControl(一个专用按钮)。我的按钮上应该有三行文字(顶部,中部,底部),这些文字按比例尺寸(1 *,3 *,1 *)。我希望文本框填充网格中的给定空间。即如果按钮是500x200,则内部文本框全部为200宽,顶部高100像素,中间高300英尺,底部高100英尺。如果按钮是700x300,Top = 140,Middle = 420,Bottom = 140。

我创建了一个具有按比例大小的行的网格,它的行为方式与我想要的一样,但我不知道如何让网格中的子元素填充网格单元格中的空间。

enter image description here

<UserControl
    x:Class="DynamicButtons.DynamicButton"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:DynamicButtons"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300"
    d:DesignWidth="400">

    <Grid Background="SlateGray">
        <Grid.RowDefinitions>
            <RowDefinition Height="1*" />
            <RowDefinition Height="3*" />
            <RowDefinition Height="1*" />
        </Grid.RowDefinitions>

        <TextBox Text="Top" Grid.Row="0" Margin="0,0,0,0" TextAlignment="Center" />
        <TextBox Text="Middle" Grid.Row="1" Margin="0,0,0,0" TextAlignment="Center" />
        <TextBox Text="Bottom" Grid.Row="2" Height="Auto" Margin="0,0,0,0" TextAlignment="Center" />
    </Grid>
</UserControl>

1 个答案:

答案 0 :(得分:1)

如果你添加VerticalAlignment =&#34; Stretch&#34;对于TextBox定义,它们将填充垂直空间。

相关问题