如何使Button的大小等于其父网格的大小?

时间:2018-07-20 09:03:25

标签: .net wpf xaml layout

我的网格中有一个按钮。事实是,按钮并不是很大,因为它只包含一个字体大小为24的文本块。

<Button VerticalAlignment="Center" HorizontalAlignment="Center" Style="{StaticResource TransparentStyle}"
    Command="{Binding Path=GetCertificateCommand}"
    Width="{Binding RelativeSource={RelativeSource AncestorType=Grid}, Path=Width}"
    Height="{Binding RelativeSource={RelativeSource AncestorType=Grid}, Path=Height}">
    <TextBlock Style="{StaticResource ForegroundSectionTitleStyle}" Text="Выбрать сертификат для подписи" />
</Button>

因此,我从文本块中获得的这个大小是不够的,因为我希望按钮更大。

我决定将其放在Grid内,然后通过Width设置按钮的HeightRelativeSource。实际上,即使我将这些值分配给此Binding,它也不会执行任何操作。

我当然可以将Button的Vertical/HorizontalAlignment设置为Stretch,将Center设置为其中的TextBlock,但是我想知道为什么显式RelativeSource分配是不起作用?

0 个答案:

没有答案