In WinUI 3, TextBox
and NumberBox
controls support a Header
property that adds text above the control to label the input field. I would like the same sort of thing for a DropDownButton
control, but the Header
property is not supported for that control.
I tried working around this limitation by wrapping the DropDownButton
with a StackPanel
to group it with a TextBlock
, but the text doesn't line up correctly with the text of the headers of other controls in the same row.
Is there a way to do this without abandoning the use of the Header
property altogether? I know that I could just not use the Header
property for any of the controls and instead have 2 rows for each row of input controls, one for text labels and another for the input controls. It seems like a kludge to do it that way.
Below is an example for illustration. In the following user control, the TextBlock
text for the B0 (T)
and Pulse Sequence
labels don't align with the headers for the other controls in the same row.
<?xml version="1.0" encoding="utf-8"?>
<UserControl
x:Class="The.Fully.Qualified.Class.Name"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid x:Name="MrAcquisitionParametersGrid"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
Style="{ThemeResource BorderedGridStyle}">
<Grid.Resources>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4"
Margin="10 10 10 0"
HorizontalAlignment="Left">
MR Acquisition Parameters
</TextBlock>
<StackPanel Grid.Row="1" Grid.Column="0">
<TextBlock Style="{StaticResource LabelTextStyle}">
B0 (T)
</TextBlock>
<DropDownButton Content="1.5" x:Name="FieldStrength">
<DropDownButton.Flyout>
<MenuFlyout>
<MenuFlyoutItem Text="1.5"/>
<MenuFlyoutItem Text="3.0"/>
<MenuFlyoutItem Text="4.7"/>
<MenuFlyoutItem Text="7.0"/>
<MenuFlyoutItem Text="9.4"/>
</MenuFlyout>
</DropDownButton.Flyout>
</DropDownButton>
</StackPanel>
<NumberBox Grid.Row="1" Grid.Column="1"
Width="90"
Header="Flip Angle (°)"
x:Name="FlipAngle"/>
<StackPanel Grid.Row="2" Grid.Column="0">
<TextBlock Style="{StaticResource LabelTextStyle}">
Pulse Sequence
</TextBlock>
<DropDownButton Content="FLASH" x:Name="PulseSequence">
<DropDownButton.Flyout>
<MenuFlyout>
<MenuFlyoutItem Text="FLASH"/>
<MenuFlyoutItem Text="RARE"/>
</MenuFlyout>
</DropDownButton.Flyout>
</DropDownButton>
</StackPanel>
<NumberBox Grid.Row="2" Grid.Column="1"
Header="Acquisition Interval (s)"
x:Name="AcquisitionInterval"/>
<NumberBox Grid.Row="2" Grid.Column="2"
Header="Echo Time (ms)"
x:Name="EchoTime"/>
<NumberBox Grid.Row="2" Grid.Column="3"
Header="Repetition Time (ms)"
x:Name="RepetitionTime"/>
</Grid>
</UserControl>