我正在尝试使用 WPF 在 MetroWindow 控件内使用 MahApps.Metro 为设置创建一个弹出窗口。我已经创建了弹出窗口并有其他几个单选按钮和分隔符。我现在添加一个数据网格来保存用作我的应用程序的监视列表的 StockSymbols 列表。我遇到的问题是正确设置数据网格,使其不会自动增长到超出弹出窗口的大小。如果您将行添加到数据网格,您可以继续添加,直到它流出窗口之外的屏幕。我想这样做,这样我就不必手动设置最大高度,并让它随着窗口的增长而动态增长。
这是我当前的弹出代码:
<Controls:MetroWindow.Flyouts>
<Controls:Flyout Header="Settings"
Background="#9f000000"
Position="Right"
IsOpen="{Binding IsSettingsFlyoutOpen}">
<DockPanel HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<StackPanel Orientation="Vertical"
VerticalAlignment="Top"
HorizontalAlignment="Center"
Margin="20,0"
DockPanel.Dock="Top">
<Label Content="Theme"
Style="{StaticResource DescriptionHeaderStyle}" />
<StackPanel Orientation="Horizontal">
<RadioButton Content="Dark"
Margin="0,0,5,0"
IsChecked="True"
Checked="ThemeDark" />
<RadioButton Content="Light"
Margin="0,0,5,0"
Checked="ThemeLight" />
</StackPanel>
<Separator Margin="0,10,0,10" />
<Label Content="Accent"
Style="{StaticResource DescriptionHeaderStyle}" />
<StackPanel Orientation="Vertical">
<RadioButton Content="Black"
Margin="0,5,0,0" />
<RadioButton Content="Blue"
Margin="0,5,0,0"
Checked="AccentBlue" />
<RadioButton Content="Red"
Margin="0,5,0,0"
Checked="AccentRed" />
<RadioButton Content="Green"
Margin="0,5,0,0"
Checked="AccentGreen" />
<RadioButton Content="Orange"
Margin="0,5,0,0"
IsChecked="True"
Checked="AccentOrange" />
<RadioButton Content="Purple"
Margin="0,5,0,0"
Checked="AccentPurple" />
</StackPanel>
<Separator Margin="0,10,0,10" />
</StackPanel>
<StackPanel Orientation="Vertical"
Height="Auto"
VerticalAlignment="Top"
DockPanel.Dock="Bottom"
Margin="20,0">
<Label Content="Watch List"
Style="{StaticResource DescriptionHeaderStyle}" />
<DataGrid ItemsSource="{Binding WatchList}"
AutoGenerateColumns="False"
CanUserResizeRows="False"
CanUserReorderColumns="False"
HeadersVisibility="Column">
<DataGrid.Columns>
<DataGridTextColumn Header="Symbol"
Binding="{Binding Symbol}" />
<DataGridTextColumn Header="Name"
Binding="{Binding Name}" />
</DataGrid.Columns>
</DataGrid>
</StackPanel>
</DockPanel>
</Controls:Flyout>
</Controls:MetroWindow.Flyouts>
任何和所有的帮助表示赞赏。