none
WPF DataGrid Column Width issue

    Question

  • I have a simple window with 2 tabs, and 4 datagrids.  I set up each one with similar, if not identical settings.  They all get their own DataSet based binding, and have standard Text columns, and combo box columns.  Recently (past week) of development, while I was adding filtering/sorting/grouping features to my program, the column widths have begun to ingore my settings.  By collapsed I mean approx 20 pixels wide (just enough for the sorting Icon).

    Contacts datagrid, works great in run time, but in design time the columns are all collapsed.

    ContactsToClients data grid has no abnormal issues

    Clients datagrid AND Clients to Contacts datagrid look great in design time, but show collapsed columns in run time.

    How do I hunt down the problem?  I've tried removing all the temporary code, and rebuilding, closing Visual Studio and reopening.  I've remmed out the sorting code.  None of these have any affect.  It appears that my settings are all being ignored.  Here is the XAML code:

     

    <Window x:Class="wdContacts"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:my="clr-namespace:TTSMain" 
      Title="Contacts" 
      Style="{StaticResource StandardWindow}" Icon="/TTSMain;component/Images/TTS%20Icon32.png">
    	<Window.TaskbarItemInfo>
    		<TaskbarItemInfo />
    	</Window.TaskbarItemInfo>
    	<Window.Resources>
        <my:TTSMainDataSet x:Key="TTSMainContactsDataSet" />
    		<my:TTSMainDataSet x:Key="TTSMainClientsDataSet" />
    		<CollectionViewSource x:Key="ContactsViewSource" x:Name="vsContacts" Source="{Binding Path=Contacts, Source={StaticResource TTSMainContactsDataSet}}" />
    		<CollectionViewSource x:Key="ClientsViewSource" Source="{Binding Path=Clients, Source={StaticResource TTSMainClientsDataSet}}" />
    		<CollectionViewSource x:Key="ContactsToClientsViewSource" x:Name="vsContact2C" Source="{Binding Path=ContactsToClients, Source={StaticResource TTSMainContactsDataSet}}" />
    		<CollectionViewSource x:Key="ClientsToContactsViewSource" x:Name="vsClient2C" Source="{Binding Path=ContactsToClients, Source={StaticResource TTSMainClientsDataSet}}" />
    		<CollectionViewSource x:Key="CityStateViewSource" x:Name="vsCityState" Source="{Binding Path=CityStateView, Source={StaticResource TTSMainContactsDataSet}}"/>
    		<CollectionViewSource x:Key="ClientTypeViewSource" x:Name="vsClientType" Source="{Binding Path=ClientType, Source={StaticResource TTSMainClientsDataSet}}"/>
    	</Window.Resources>
      <Grid Name="grdWindow" DataContext="{StaticResource ContactsViewSource}" Margin="0">
        <TabControl Name="tcWindow" Padding="5" Margin="5">
          <TabItem Name="tiContacts" Header="Contacts">
            <Grid Name="grdContacts" Margin="2">
              <Grid.RowDefinitions>
                <RowDefinition Height="36" />
                <RowDefinition Height="391" />
                <RowDefinition Height="41" />
                <RowDefinition Height="213*" />
              </Grid.RowDefinitions>
              <Grid.ColumnDefinitions>
                <ColumnDefinition Width="10" />
                <ColumnDefinition Width="360*" />
                <ColumnDefinition Width="10" />
                <ColumnDefinition Width="595*" />
              </Grid.ColumnDefinitions>
              <DataGrid Name="dgContacts" AutoGenerateColumns="False" EnableRowVirtualization="True" 
                   ItemsSource="{Binding}" RowDetailsVisibilityMode="VisibleWhenSelected" 
                   CanUserDeleteRows="False" CanUserAddRows="False" Grid.Column="1" Grid.Row="1" Grid.RowSpan="3" 
    							 Style="{StaticResource StandardDataGrid}" >
    						<DataGrid.GroupStyle>
    							<GroupStyle>
    								<GroupStyle.ContainerStyle>
    									<Style BasedOn="{StaticResource StandardGroupItem}" TargetType="{x:Type GroupItem}"/>
    								</GroupStyle.ContainerStyle>
    							</GroupStyle>
    						</DataGrid.GroupStyle>
    						<DataGrid.ContextMenu>
    							<ContextMenu>
    								<MenuItem x:Name="miGroupContacts" Header="Group By">
    									<MenuItem.Icon>
    										<Image Source="/TTSMain;component/Images/17.png" />
    									</MenuItem.Icon>
    								</MenuItem>
    							</ContextMenu>
    						</DataGrid.ContextMenu>
    						<DataGrid.Columns>
                  <DataGridTextColumn x:Name="dgCID" Binding="{Binding Path=ID}" Header="ID" IsReadOnly="True" Width="SizeToHeader" Visibility="Hidden" />
                  <DataGridTextColumn x:Name="dgCFirstName" Binding="{Binding Path=FirstName}" Header="First Name" Width="*" CanUserResize="True" />
    							<DataGridTextColumn x:Name="dgCMiddleInit" Binding="{Binding Path=MiddleInitial}" Header="MI" Width="SizeToHeader" />
                  <DataGridTextColumn x:Name="dgCLastName" Binding="{Binding Path=LastName}" Header="Last Name" Width="*" />
                </DataGrid.Columns>
              </DataGrid>
              <Grid Name="grdContactDetails" HorizontalAlignment="Left" VerticalAlignment="Top" Width="Auto" Grid.Column="3" Grid.Row="1" >
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="Auto" />
                  <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Label Content="First Name:" Grid.Column="0" Grid.Row="1" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
                <TextBox Name="txtFirstName" Style="{StaticResource StandardTextBox}" Grid.Column="1" Grid.Row="1" HorizontalAlignment="Left" 
                     Margin="3" Text="{Binding Path=FirstName, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" 
                     VerticalAlignment="Center" Width="200" HorizontalContentAlignment="Left" />
                <Label Content="Middle Initial:" Grid.Column="0" Grid.Row="2" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
                <TextBox Name="txtMiddleInit" Style="{StaticResource StandardTextBox}" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Left" 
                     Margin="3" Text="{Binding Path=MiddleInitial, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" 
                     VerticalAlignment="Center" Width="200" HorizontalContentAlignment="Left" />
                <Label Content="Last Name:" Grid.Column="0" Grid.Row="3" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
                <TextBox Name="txtLastname" Style="{StaticResource StandardTextBox}" Grid.Column="1" Grid.Row="3" HorizontalAlignment="Left" 
                     Margin="3" Text="{Binding Path=LastName, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" 
                     VerticalAlignment="Center" Width="200" HorizontalContentAlignment="Left" />
                <Label Content="CityState:" Grid.Column="0" Grid.Row="5" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
                <ComboBox Name="cbxCityState" 
                     Style="{StaticResource StandardComboBox}" 
                     IsEditable="True" StaysOpenOnEdit="True" Grid.Column="1" Grid.Row="5" 
                     HorizontalAlignment="Left" Margin="3,3,0,3" 
                     Text="{Binding Path=Location, Mode=OneWay, ValidatesOnExceptions=true, NotifyOnValidationError=true, Converter={StaticResource cityStateConverter}}" 
                     VerticalAlignment="Center" 
                     HorizontalContentAlignment="Left" 
                     ItemsSource="{Binding Source={StaticResource CityStateViewSource}}" 
                     DisplayMemberPath="CityState" Width="180" />
                <Label Content="Zip:" Grid.Column="0" Grid.Row="6" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
                <TextBox Name="txtZip" Style="{StaticResource StandardTextBox}" Grid.Column="1" Grid.Row="6" HorizontalAlignment="Left" 
                     Margin="3" Text="{Binding Path=Zip, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" 
                     VerticalAlignment="Center" Width="200" HorizontalContentAlignment="Left" />
                <Label Content="Address 1:" Grid.Column="0" Grid.Row="7" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
                <TextBox Name="txtAddress1" Style="{StaticResource StandardTextBox}" Grid.Column="1" Grid.Row="7" HorizontalAlignment="Left" 
                     Margin="3" Text="{Binding Path=Address1, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" 
                     VerticalAlignment="Center" Width="200" HorizontalContentAlignment="Left" />
                <Label Content="Address 2:" Grid.Column="0" Grid.Row="8" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
                <TextBox Name="txtAddress2" Style="{StaticResource StandardTextBox}" Grid.Column="1" Grid.Row="8" HorizontalAlignment="Left" 
                     Margin="3" Text="{Binding Path=Address2, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" 
                     VerticalAlignment="Center" Width="200" HorizontalContentAlignment="Left" />
                <Label Content="Work Phone:" Grid.Column="0" Grid.Row="9" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
                <TextBox Name="txtWorkPhone" Style="{StaticResource StandardTextBox}" Grid.Column="1" Grid.Row="9" HorizontalAlignment="Left" 
                     Margin="3" 
                     Text="{Binding Path=WorkPhone, 
                      Mode=TwoWay, 
                      ValidatesOnExceptions=true, 
                      NotifyOnValidationError=true,
                      Converter={StaticResource phoneNumberConverter}}" 
                     VerticalAlignment="Center" Width="200" HorizontalContentAlignment="Left" />
                <Label Content="Cell Phone:" Grid.Column="0" Grid.Row="10" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
                <TextBox Name="txtCellPhone" Style="{StaticResource StandardTextBox}" Grid.Column="1" Grid.Row="10" HorizontalAlignment="Left" 
                     Margin="3" 
                     Text="{Binding Path=CellPhone, 
                      Mode=TwoWay, 
                      ValidatesOnExceptions=true, 
                      NotifyOnValidationError=true,
                      Converter={StaticResource phoneNumberConverter}}" 
                     VerticalAlignment="Center" Width="200" HorizontalContentAlignment="Left" />
                <Label Content="Other Phone:" Grid.Column="0" Grid.Row="11" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
                <TextBox Name="txtOtherPhone" Style="{StaticResource StandardTextBox}" Grid.Column="1" Grid.Row="11" HorizontalAlignment="Left" 
                     Margin="3" 
                     Text="{Binding Path=OtherPhone,
                      Mode=TwoWay, 
                      ValidatesOnExceptions=true, 
                      NotifyOnValidationError=true,
                      Converter={StaticResource phoneNumberConverter}}" 
                     VerticalAlignment="Center" Width="200" HorizontalContentAlignment="Left" />
                <Label Content="Website:" Grid.Column="0" Grid.Row="12" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
                <TextBox Name="txtWebsite" Style="{StaticResource StandardTextBox}" Grid.Column="1" Grid.Row="12" HorizontalAlignment="Left" 
                     Margin="3" Text="{Binding Path=Website, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" 
                     VerticalAlignment="Center" Width="200" HorizontalContentAlignment="Left" />
                <Label Content="Email:" Grid.Column="0" Grid.Row="13" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
                <TextBox Name="txtEmail" Style="{StaticResource StandardTextBox}" Grid.Column="1" Grid.Row="13" HorizontalAlignment="Left" 
                     Margin="3" Text="{Binding Path=Email, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" 
                     VerticalAlignment="Center" Width="200" HorizontalContentAlignment="Left" />
                <Label Content="Notes:" Grid.Column="0" Grid.Row="14" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
                <TextBox Name="txtNotes" Style="{StaticResource StandardTextBox}" Grid.Column="1" Grid.Row="14" HorizontalAlignment="Left" 
                     Margin="3" Text="{Binding Path=Notes, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" 
                     VerticalAlignment="Center" Width="200" HorizontalContentAlignment="Left" />
    						<Button Content="..." Grid.Column="1" Grid.Row="5" Name="btnCurrentLocation" Style="{StaticResource EllipsisButton}" Margin="2" />
    					</Grid>
              <DataGrid Name="dgContactsToClients" AutoGenerateColumns="False" EnableRowVirtualization="True"
                   ItemsSource="{Binding Source={StaticResource ContactsToClientsViewSource}}" 
                   RowDetailsVisibilityMode="VisibleWhenSelected" 
                   CanUserAddRows="False" CanUserDeleteRows="False" 
                   Grid.Column="3" Grid.Row="3" Style="{StaticResource StandardDataGrid}">
    						<DataGrid.GroupStyle>
    							<GroupStyle>
    								<GroupStyle.ContainerStyle>
    									<Style BasedOn="{StaticResource StandardGroupItem}" TargetType="{x:Type GroupItem}"/>
    								</GroupStyle.ContainerStyle>
    							</GroupStyle>
    						</DataGrid.GroupStyle>
    						<DataGrid.ContextMenu>
    							<ContextMenu>
    								<MenuItem x:Name="miGroupContactsToClients" Header="Group By">
    									<MenuItem.Icon>
    										<Image Source="/TTSMain;component/Images/17.png" />
    									</MenuItem.Icon>
    								</MenuItem>
    							</ContextMenu>
    						</DataGrid.ContextMenu>
                <DataGrid.Columns>
                  <DataGridTextColumn x:Name="dgcC2CID" Binding="{Binding Path=ID}" Header="ID" IsReadOnly="True" Width="SizeToHeader" Visibility="Hidden" />
    							<DataGridTextColumn x:Name="dgcC2CClient" Header="Client" Binding="{Binding Path=ClientID, Converter={StaticResource clientIDToNameConverter}}" Width="200*" />
                  <DataGridTextColumn x:Name="dgcC2CContactPriority" CellStyle="{StaticResource DataGridCellCenter}" Binding="{Binding Path=ContactPriority}" 
                            Header="Priority" Width="95*" />
                  <DataGridCheckBoxColumn x:Name="dgcC2CIsAccounting" Binding="{Binding Path=IsAccounting}" Header="Accounting" Width="90*" />
                  <DataGridCheckBoxColumn x:Name="dgcC2CIsEngineering" Binding="{Binding Path=IsEngineering}" Header="Engineering" Width="90*" />
                  <DataGridCheckBoxColumn x:Name="dgcC2CIsOfficeLocation" Binding="{Binding Path=IsOfficeLocation}" Header="Office Location" Width="110*" />
                </DataGrid.Columns>
              </DataGrid>
              <ToolBar x:Name="tbContacts" Height="31" VerticalAlignment="Top" Band="1" BandIndex="1" Margin="0" Grid.Column="1" Grid.ColumnSpan="3">
    						<Label Name="lbContacts" Content="Contacts: " Style="{StaticResource ToolBarHeaderLabel}" />
    						<Button Name="btnSelectContact" Content="OK" Style="{StaticResource ToolBarButton}" ToolTip="Use Selected Contact" Visibility="Collapsed" />
    						<ToggleButton Name="btnEditContact" ToolTip="Unlock for Edit" Style="{StaticResource OpenForWriteButton}"/>
    						<Button Name='btnSaveContact' Style="{StaticResource ToolBarButton}" ToolTip="Save" >
                  <Button.Background>
                    <ImageBrush ImageSource="/TTSMain;component/Images/BlueFloppy.png" Stretch="None" TileMode="None" />
                  </Button.Background>
                </Button>
    						<Button x:Name="btnNewLocation" Style="{StaticResource ToolBarButton}" >
    							<Button.Background>
    								<ImageBrush ImageSource="/TTSMain;component/Images/44.png" Stretch="None" TileMode="None" />
    							</Button.Background>
    						</Button>						
    						<Button Name='btnDeleteContact' Style="{StaticResource ToolBarButton}" Margin="35,0" >
                  <Button.Background>
                    <ImageBrush ImageSource="/TTSMain;component/Images/RedX.png" Stretch="None" TileMode="None" />
                  </Button.Background>
                </Button>
    						<Label Name="lbSearchContacts" Content="Search Text: " Style="{StaticResource ToolBarStandardLabel}" />
    						<TextBox x:Name="txtSearchContacts" Style="{StaticResource StandardTextBox}" Width="150" Background="#77FFFFFF" BorderBrush="#FFA5ACB2" />
    						<Label Name="lbSearchContactsField" Content="Search Field: " Style="{StaticResource ToolBarStandardLabel}" />
    						<ComboBox Name="cbxContactsSearchFields" Style="{StaticResource StandardComboBox}" 
    								 Width="130" Background="#77FFFFFF" BorderBrush="#FFA5ACB2" 
    								 AllowDrop="True" />
    						<ToggleButton Name="btnSearchContacts" ToolTip="Filter" Style="{StaticResource FilterButton}"/>
    						<Button Name="btnRefresh" Style="{StaticResource RefreshToolBarButton}" />
    					</ToolBar>
              <ToolBar Name="tbContacts2Clients" Band="1" BandIndex="1" Height="31" 
                   Margin="0" VerticalAlignment="Top" Grid.Column="3" Grid.Row="2" Grid.ColumnSpan="1" DataContext="{Binding}">
    						<Label Name="lbRelatedClients" Content="Related Clients: " Style="{StaticResource ToolBarHeaderLabel}" />
    						<ToggleButton Name="btnEditC2C" ToolTip="Unlock for Edit" Style="{StaticResource OpenForWriteButton}"/>
    						<Button Name="btnSaveC2C" Style="{StaticResource ToolBarButton}">
                  <Button.Background>
                    <ImageBrush ImageSource="/TTSMain;component/Images/BlueFloppy.png" Stretch="None" TileMode="None" />
                  </Button.Background>
                </Button>
    						<Button Name="btnDeleteC2C" Style="{StaticResource ToolBarButton}" Margin="35,0" >
                  <Button.Background>
                    <ImageBrush ImageSource="/TTSMain;component/Images/RedX.png" Stretch="None" TileMode="None" />
                  </Button.Background>
                </Button>
              </ToolBar>
    				</Grid>
          </TabItem>
          <TabItem Header="Clients" Name="tiClients">
    				<Grid Name="grdClients" Margin="2">
    					<Grid.RowDefinitions>
    						<RowDefinition Height="36" />
    						<RowDefinition Height="645*" />
    					</Grid.RowDefinitions>
    					<Grid.ColumnDefinitions>
    						<ColumnDefinition Width="10" />
    						<ColumnDefinition Width="490*" />
    						<ColumnDefinition Width="10" />
    						<ColumnDefinition Width="465*" />
    					</Grid.ColumnDefinitions>
    					<DataGrid Name="dgClients" 
    							 AutoGenerateColumns="False" 
    							 EnableRowVirtualization="True" 
    							 ItemsSource="{Binding Source={StaticResource ClientsViewSource}}" 
    							 RowDetailsVisibilityMode="VisibleWhenSelected" 
    							 Style="{StaticResource StandardDataGrid}"
    							 Grid.Column="1" Grid.Row="1" >
    						<DataGrid.GroupStyle>
    							<GroupStyle>
    								<GroupStyle.ContainerStyle>
    									<Style BasedOn="{StaticResource StandardGroupItem}" TargetType="{x:Type GroupItem}"/>
    								</GroupStyle.ContainerStyle>
    							</GroupStyle>
    						</DataGrid.GroupStyle>
    						<DataGrid.ContextMenu>
    							<ContextMenu>
    								<MenuItem x:Name="miGroupClients" Header="Group By">
    									<MenuItem.Icon>
    										<Image Source="/TTSMain;component/Images/17.png" />
    									</MenuItem.Icon>
    								</MenuItem>
    							</ContextMenu>
    						</DataGrid.ContextMenu>
    						<DataGrid.Columns>
    							<DataGridTextColumn x:Name="IDColumn" Binding="{Binding Path=ID}" Header="ID" IsReadOnly="True" Width="SizeToHeader" Visibility="Hidden" />
    							<DataGridTextColumn x:Name="NameColumn" Binding="{Binding Path=Name}" Header="Name" Width="180*" />
    							<DataGridTextColumn x:Name="NameAbbrevColumn" Binding="{Binding Path=NameAbbrev}" Header="Abbrev" Width="50*" />
    							<DataGridTextColumn x:Name="MainOfficeColumn" Binding="{Binding Path=MainOffice, Converter={StaticResource contactIDToMainOfficeConverter}}" Header="Main Office" Width="140*" IsReadOnly="True" />
    							<DataGridComboBoxColumn x:Name="ClientTypeColumn" 
    									SelectedValueBinding="{Binding Path=ClientType}"
    									SelectedValuePath="ID"
    									DisplayMemberPath="Name"
    									ItemsSource="{Binding Source={StaticResource ClientTypeViewSource}}" 
    									Header="Client Type" Width="90*" />
    						</DataGrid.Columns>
    					</DataGrid>
    					<DataGrid Name="dgClientsToContacts" 
    							 AutoGenerateColumns="False" 
    							 EnableRowVirtualization="True" 
    							 ItemsSource="{Binding Source={StaticResource ClientsToContactsViewSource}}" 
    							 RowDetailsVisibilityMode="VisibleWhenSelected" 
    							 Style="{StaticResource StandardDataGrid}"
    							 Grid.Column="3" Grid.Row="1" >
    						<DataGrid.GroupStyle>
    							<GroupStyle>
    								<GroupStyle.ContainerStyle>
    									<Style BasedOn="{StaticResource StandardGroupItem}" TargetType="{x:Type GroupItem}"/>
    								</GroupStyle.ContainerStyle>
    							</GroupStyle>
    						</DataGrid.GroupStyle>
    						<DataGrid.ContextMenu>
    							<ContextMenu>
    								<MenuItem x:Name="miGroupClientsToContacts" Header="Group By">
    									<MenuItem.Icon>
    										<Image Source="/TTSMain;component/Images/17.png" />
    									</MenuItem.Icon>
    								</MenuItem>
    							</ContextMenu>
    						</DataGrid.ContextMenu>
    						<DataGrid.Columns>
    							<DataGridTextColumn x:Name="dgcCl2CID" Binding="{Binding Path=ID}" Header="ID" IsReadOnly="True" Width="30" Visibility="Hidden" MinWidth="30" />
    							<DataGridTextColumn x:Name="dgcCl2CClientID" Binding="{Binding Path=ClientID}" Header="Client ID" Width="SizeToHeader" Visibility="Hidden" />
    							<DataGridTextColumn x:Name="dgcCl2CContactID" Binding="{Binding Path=ContactID, Converter={StaticResource contactIDToNameConverter}}" Header="Contact" Width="150*" MinWidth="20" />
    							<DataGridTextColumn x:Name="dgcCl2CContactPriority" Binding="{Binding Path=ContactPriority}" Header="Priority" Width="60*" />
    							<DataGridCheckBoxColumn x:Name="dgcCl2CIsAccounting" Binding="{Binding Path=IsAccounting}" Header="Accounting" Width="80*" MinWidth="30" />
    							<DataGridCheckBoxColumn x:Name="dgcCl2CIsEngineering" Binding="{Binding Path=IsEngineering}" Header="Engineering" Width="80*" />
    							<DataGridCheckBoxColumn x:Name="dgcCl2CIsOfficeLocation" Binding="{Binding Path=IsOfficeLocation}" Header="Office Location" Width="100*" />
    						</DataGrid.Columns>
    					</DataGrid>
    					<ToolBar Band="1" BandIndex="1" Grid.Column="1" Grid.ColumnSpan="3" Height="31" Name="tbClients" VerticalAlignment="Top">
    						<Label Content="Clients: " Name="lblClients" Style="{StaticResource ToolBarHeaderLabel}" />
    						<ToggleButton Name="btnEditClient" Style="{StaticResource OpenForWriteButton}" ToolTip="Open for write."/>
    						<Button Name="btnSaveClient" Style="{StaticResource ToolBarButton}" ToolTip="Save">
    							<Button.Background>
    								<ImageBrush ImageSource="/TTSMain;component/Images/BlueFloppy.png" Stretch="None" TileMode="None" />
    							</Button.Background>
    						</Button>
    						<Button Name="btnDeleteClient" Margin="35,0" Style="{StaticResource ToolBarButton}">
    							<Button.Background>
    								<ImageBrush ImageSource="/TTSMain;component/Images/RedX.png" Stretch="None" TileMode="None" />
    							</Button.Background>
    						</Button>
    						<Label Name="lblSearchText" Content="Search Text: " Style="{StaticResource ToolBarStandardLabel}" />
    						<TextBox Name="txtSearchClient" Background="#77FFFFFF" BorderBrush="#FFA5ACB2" Style="{StaticResource StandardTextBox}" Width="100" />
    						<Label Name="lbSearchField" Content="Search Field: " Style="{StaticResource ToolBarStandardLabel}" />
    						<ComboBox Name="cbxClientSearchFields" AllowDrop="True" Background="#77FFFFFF" BorderBrush="#FFA5ACB2" Style="{StaticResource StandardComboBox}" Width="100" />
    						<ToggleButton Name="tgbFilterClient" Style="{StaticResource FilterButton}" ToolTip="Filter" />
    					</ToolBar>
    				</Grid> 
          </TabItem>
        </TabControl>
      </Grid>
    </Window>
    Tuesday, September 07, 2010 10:58 PM

Answers

  • Hi JamieVJohnson,

    Please specify the GroupStyle.Panel to the DataGridRowsPresenter in DataGrid, since the default GroupStyle.Panel (StackPanel) cannot fit for the DataGrid Width "*" and the columns collapse.

     <DataGrid Height="100">
      <DataGrid.GroupStyle>
      <GroupStyle>
       <GroupStyle.Panel>
       <ItemsPanelTemplate>
        <DataGridRowsPresenter/>
       </ItemsPanelTemplate>
       </GroupStyle.Panel>
       <GroupStyle.ContainerStyle>
       <Style TargetType="{x:Type GroupItem}">
        ...
       </Style>
       </GroupStyle.ContainerStyle>
      </GroupStyle>
      </DataGrid.GroupStyle>
      <DataGrid.Columns>
      <DataGridTextColumn Header="Column 1" Width="2*"/>
      <DataGridTextColumn Header="Column 2" Width="1*"/>
      </DataGrid.Columns>
     </DataGrid>
    

    Sincerely,

    Bob Bao


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Are you looking for a typical code sample? Please download all in one code framework !
    • Marked as answer by JamieVJohnson Thursday, September 09, 2010 4:58 PM
    Thursday, September 09, 2010 7:44 AM
    Moderator

All replies

  • Update,

    The datagrid will display the proper width If I take the Dynamic "*" out of the equations.  If I put just one * in it, they all collapse.  This is a new (and wrong) behavior, and I would like to fix it.  Any ideas?  I read mention of an issue with DataGrid's on second page of a tab control, Mine is the same, are these related bugs?

     

    jvj

    Wednesday, September 08, 2010 2:09 PM
  • Hi JamieVJohnson,

    Please specify the GroupStyle.Panel to the DataGridRowsPresenter in DataGrid, since the default GroupStyle.Panel (StackPanel) cannot fit for the DataGrid Width "*" and the columns collapse.

     <DataGrid Height="100">
      <DataGrid.GroupStyle>
      <GroupStyle>
       <GroupStyle.Panel>
       <ItemsPanelTemplate>
        <DataGridRowsPresenter/>
       </ItemsPanelTemplate>
       </GroupStyle.Panel>
       <GroupStyle.ContainerStyle>
       <Style TargetType="{x:Type GroupItem}">
        ...
       </Style>
       </GroupStyle.ContainerStyle>
      </GroupStyle>
      </DataGrid.GroupStyle>
      <DataGrid.Columns>
      <DataGridTextColumn Header="Column 1" Width="2*"/>
      <DataGridTextColumn Header="Column 2" Width="1*"/>
      </DataGrid.Columns>
     </DataGrid>
    

    Sincerely,

    Bob Bao


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Are you looking for a typical code sample? Please download all in one code framework !
    • Marked as answer by JamieVJohnson Thursday, September 09, 2010 4:58 PM
    Thursday, September 09, 2010 7:44 AM
    Moderator
  • I did so, and it worked. Just adding these 5 lines:

       <GroupStyle.Panel>
       <ItemsPanelTemplate>
        <DataGridRowsPresenter/>
       </ItemsPanelTemplate>
       </GroupStyle.Panel>

    If I get it right, I moved the DataGridRowsPresenter, which is responsible for hosting all the rows, into the custom GroupStyle's panel.

    Thank you,

    jvj

    Thursday, September 09, 2010 5:01 PM
  • Thank you Bob,

    This solved a similar problem for me, using the WPF 4.0 Datagrid, where the columns would be incorrectly sized (collapsed to minimum specified sizes) the first time the grid was display & then correctly when the datasource was updated.

    It was driving me crazy & I had no idea why this was happening, until I stumbled on this post, looking for something else.

    Is this something that will be "fixed" at some stage, or is this expected beahvior that will remain as it is, the only solution being adding those lines?

    Thanks again,

    Yann

    Sunday, February 13, 2011 10:09 PM
  • I have used the solution and i works perfectly with one problem. I have CollectionView with explicitly defined groups. If the number of items in collection is less then the number of groups only the same number of groups as the number of items is displayed.  With StackPanel as ItemsPanelTemplate the groups are shown correctly but there is a problem with column collapsing. Does anybody know a solution of this problem?
    Thursday, June 09, 2011 8:45 PM
  • Yes; I have exactly the same problem with the DataGridRowsPresenter it doesn't work well with empty groups.  Are there any other ideas out there?  

    I did try replacing the StackPanel with a custom DockPanel (which forces children to dock top) and I find the same problem with the column sizes.

    Thursday, June 07, 2012 7:47 PM