我的网格中有一个按钮。事实是,按钮并不是很大,因为它只包含一个字体大小为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
设置按钮的Height
和RelativeSource
。实际上,即使我将这些值分配给此Binding,它也不会执行任何操作。
我当然可以将Button的Vertical/HorizontalAlignment
设置为Stretch
,将Center
设置为其中的TextBlock
,但是我想知道为什么显式RelativeSource
分配是不起作用?