0

したがって、グリッド列のウィンドウにボタンがあります。ボタンを以下に示します。

<Button>
    <Border BorderThickness="3" BorderBrush="Red">
        <Grid Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button, AncestorLevel=1}, Path=Width}">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
                <TextBlock Grid.Row="0" Background="LightBlue">bunnies</TextBlock>
            <TextBlock Grid.Row="1" Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button, AncestorLevel=1}, Path=Width}" Background="LightBlue">bunnies</TextBlock>
        </Grid>
    </Border>
</Button>

私が見ているのは、下の一番左のボタンの例です。下の 2 のようにしたいと思います。

編集: 最初の TextBlock に Width="1000" を追加すると、必要な効果が得られますが、テキストが列の中央になく、幅 1000 のブロックの中央にあることを除きます。だから私が求めているのは、実際の列幅または実際のボタン幅のバインディング構文です。

単一の列定義の幅を変更したり、バインドしたり、あらゆる種類のことを試してみました。

左 = 1 右 = 2

テキストの危険な編集は無視してください。境界線がボタンの端に届くようにしたいだけです。ありがとう

4

1 に答える 1

2

これを試して:

<Button HorizontalContentAlignment="Stretch">
            <Border BorderThickness="3" BorderBrush="Red">
                <Grid HorizontalAlignment="Stretch">
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Row="0" TextAlignment="Center" Background="LightBlue">bunnies</TextBlock>
                    <TextBlock Grid.Row="1" TextAlignment="Center" Background="LightBlue">bunnies</TextBlock>
                </Grid>
            </Border>
        </Button>
于 2012-10-16T19:35:31.783 に答える