The following example demonstrates how to stretch all the columns in a grid equally so that they occupy the full width available in the viewport.
XAML |
Copy Code |
---|---|
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"> <Grid.Resources> <xcdg:DataGridCollectionViewSource x:Key="cvs_orders" Source="{Binding Source={x:Static Application.Current}, Path=Orders}" AutoCreateItemProperties="False"> <xcdg:DataGridCollectionViewSource.ItemProperties> <xcdg:DataGridItemProperty Name="ShipCountry" /> <xcdg:DataGridItemProperty Name="ShipCity" /> <xcdg:DataGridItemProperty Name="ShipRegion" /> <xcdg:DataGridItemProperty Name="ShipVia" /> </xcdg:DataGridCollectionViewSource.ItemProperties> </xcdg:DataGridCollectionViewSource> </Grid.Resources> <xcdg:DataGridControl x:Name="OrdersGrid" ItemsSource="{Binding Source={StaticResource cvs_orders}}"> <xcdg:DataGridControl.View> <xcdg:TableView ColumnStretchMode="All" ColumnStretchMinWidth="100"/> </xcdg:DataGridControl.View> </xcdg:DataGridControl> </Grid> |
VB.NET |
Copy Code |
---|---|
Dim collectionView As New DataGridCollectionView( Orders, GetType( System.Data.DataRow ), False, False ) collectionView.ItemProperties.Add( New DataGridItemProperty( "ShipCountry", GetType( String ) ) ) collectionView.ItemProperties.Add( New DataGridItemProperty( "ShipCity", GetType( String ) ) ) collectionView.ItemProperties.Add( New DataGridItemProperty( "ShipRegion", GetType( String ) ) ) collectionView.ItemProperties.Add( New DataGridItemProperty( "ShipVia", GetType( Integer ) ) ) Dim view As New TableView() view.ColumnStretchMode = ColumnStretchMode.All view.ColumnStretchMinWidth = 100 dataGridControl.View = view dataGridControl.ItemsSource = collectionView |
C# |
Copy Code |
---|---|
DataGridCollectionView collectionView = new DataGridCollectionView( Orders, typeof( System.Data.DataRow ), false, false ); collectionView.ItemProperties.Add( new DataGridItemProperty( "ShipCountry", typeof( string ) ) ); collectionView.ItemProperties.Add( new DataGridItemProperty( "ShipCity", typeof( string ) ) ); collectionView.ItemProperties.Add( new DataGridItemProperty( "ShipRegion", typeof( string ) ) ); collectionView.ItemProperties.Add( new DataGridItemProperty( "ShipVia", typeof( int) ) ); TableView view = new TableView(); view.ColumnStretchMode = ColumnStretchMode.All; view.ColumnStretchMinWidth = 100; dataGridControl.View = view; dataGridControl.ItemsSource = collectionView; |