いくつかのデータ入力 TextBoxes を含む WPF ページがあり、フォントのニーズよりもはるかに大きく見えます。テキストボックスの高さを決定するものは何ですか? それらをつぶす方法はありますか?
テキストボックスは、表示されるフォントサイズに応じて大きくなったり小さくなったりします(そのため、できれば高さプロパティを直接設定したくありません.
これが私が意味することの例です...
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Page.Resources>
<Style x:Key="LabelStyle" TargetType="Label">
<Setter Property="HorizontalAlignment" Value="Right"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
</Style>
<Style x:Key="TextBoxStyle" TargetType="TextBox">
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
</Style>
</Page.Resources>
<StackPanel>
<WrapPanel>
<Label Style="{StaticResource LabelStyle}" Content="{Binding ActualHeight, RelativeSource={RelativeSource Self}}"/>
<TextBox Style="{StaticResource TextBoxStyle}" Text="{Binding ActualHeight, RelativeSource={RelativeSource Self}, Mode=OneWay}"/>
</WrapPanel>
<WrapPanel>
<Label Style="{StaticResource LabelStyle}" Content="{Binding ActualHeight, RelativeSource={RelativeSource Self}}"/>
<TextBox Style="{StaticResource TextBoxStyle}" Text="{Binding ActualHeight, RelativeSource={RelativeSource Self}, Mode=OneWay}"/>
</WrapPanel>
</StackPanel>
</Page>
サイズを見ると、ラベルがテキスト ボックスよりも少し大きいことがわかります。テキストボックスの VerticalAlignment を Top に変更すると、同じサイズになります。暫定的な措置として、ラベルの余白を -2 に設定しました。