views:

439

answers:

1

I have a DataGrid embedded inside the first column of a Grid. I want the grid column to auto size to content, but when I do this and the DataGrid gets too wide (when columns are added by the user) the DataGrid is clipped by the containing column. Essentially I need to retain the scrolling behaviour of the DataGrid, but have the DataGrid shrink to content and never be clipped.

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data">
<Border x:Name="LayoutRoot" Background="White">
 <Grid HorizontalAlignment="Stretch">
  <Grid.RowDefinitions>
   <RowDefinition
    Height="Auto" />
   <RowDefinition
    Height="Auto" />
  </Grid.RowDefinitions>
  <Grid.ColumnDefinitions>
   <ColumnDefinition
    Width="Auto" />
  </Grid.ColumnDefinitions>
  <Border><!--Toolbar content goes here--></Border>
  <data:DataGrid
   MaxHeight="350"
   Grid.Row="1" />
 </Grid>
</Border>

A: 

Have you tried something like:

<ColumnDefinition Width="Auto" MinWidth="80" MaxWidth="200"/>
JasonRShaver
I don't want to set a maximum width as I would like the grid to get as wide as it's container (when the browser window is resized).
Flatliner DOA