我有一个带 3 列的 DataGrid。第一列单元格是一个组合,用户可以从中选择不同长度的值。我希望第一列显示所选项目的整个值(即它的大小应该适合其内容)。这在我设置列的宽度 =“自动”时有效。问题出在某个时刻,当网格的整个宽度被占用时,滚动条就会出现。相反,我宁愿数据网格本身总是扩展,因此它的容器。我该怎么做..我的xaml的结构如下
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<local:MyUserControl... Grid.Col="1">
<Expander Grid.Column="2">
<GroupBox Template="{Binding OptionsSelectorTemplate}" Grid.Row="1" />
</Expander
</Grid>
<ControlTemplate x:Key="OptionsSelectorTemplate">
<StackPanel Orientation="Vertical">
<dxl:NavBarControl...>
<dxn:NavBarControl.Groups>
<dxn:NavBarGroup Header="Options Set 1">
<DataGrid Style="{StaticResource DataGridTemplateStyle}" ItemSource="{Binding ViewModel.Options}" DataContext="{Binding .}"/>
</dxn:NavBarGroup>
<dxn:NavBarGroup Header="Options Set 2">
<DataGrid Style="{StaticResource DataGridTemplateStyle}" ItemSource="{Binding ViewModel.Options}" DataContext="{Binding .}"/>
</dxn:NavBarGroup>
</dxl:NavBarControl...>
<Button ... />
</StackPanel>
</ControlTemplate>
<Style x:Key="DataGridTemplateStyle" TargetType="DataGrid">
<Setter Property="Template" Value="{StaticResource DataGridTemplate}" />
</Style>
<ControlTemplate x:Key="DataGridTemplate">
<DockPanel HorizontalAlignment="Stretch">
<DataGrid Name="_dataGrid"
AutoGenerateColumns="False" RowHeaderWidth="0" HeadersVisibility="Column" CanUserAddRows="False" GridLinesVisibility="None" HorizontalAlignment="Stretch" KeyboardNavigation.TabNavigation="Cycle">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Col1" MinWidth="75" Width="Auto" KeyboardNavigation.IsTabStop="False">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox.../> <---Want this guy to size to always fit the selected list item and to expand the entire datagrid if need be w/o displaying horizontal scroll bar.
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Weight" MinWidth="40" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Border >
<TextBox T../>
</Border>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="NN" Width="30">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox .../>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</DockPanel>
</ControlTemplate>