WPF -- Expander when collapsed does not resize other grid columns - c#

I am trying to collapse expander when when it collapse the other grid columns doesnot take up space.
I tried this in expander_collapsed, the grids are taking the whole space but then I am not able access expander only to make it expand.
private void Expander_Expanded(object sender, RoutedEventArgs e)
{
groupBoxMain.Visibility = Visibility.Visible;
}
private void Expander_Collapsed(object sender, RoutedEventArgs e)
{
MainGrid.ColumnDefinitions[0].Width = new GridLength(1, GridUnitType.Star);
groupBoxMain.Visibility = Visibility.Hidden;
}
xaml code:
<Grid x:Name="MainGrid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="Auto" Width="Auto">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="90*"/>
<ColumnDefinition Width="177*"/>
<ColumnDefinition Width="133*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="Auto" Width="Auto">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="8*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="680*"/>
<RowDefinition Height="31*"/>
</Grid.RowDefinitions>
<GroupBox Name="groupBoxMain" BorderBrush="Black" Grid.ColumnSpan="3" Grid.Column="1" Grid.Row="0" Margin="0,0,0,6">
<DataGrid Background="DarkGray" CanUserResizeColumns="True" CanUserSortColumns="True">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding BackupVersionNumber}" Header="File Name" MinWidth="100" FontFamily="Default Font" FontSize="16"/>
<DataGridTextColumn Binding="{Binding BackupDateTime}" Header="Total Time" MinWidth="100" FontFamily="Default Font" FontSize="16"/>
<DataGridTextColumn Binding="{Binding SavedBy}" Header="Total Packet" MinWidth="100" FontFamily="Default Font" FontSize="16"/>
</DataGrid.Columns>
</DataGrid>
</GroupBox>
<Expander ExpandDirection="Right" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="0" IsExpanded="True" Width="35" Grid.Row="0" Expanded="Expander_Expanded" Collapsed="Expander_Collapsed">
<Expander.Header>
<TextBlock Text="Select Manifest File" Width="Auto"
FontSize="11">
<TextBlock.LayoutTransform>
<TransformGroup>
<RotateTransform Angle="90"/>
</TransformGroup>
</TextBlock.LayoutTransform>
</TextBlock>
</Expander.Header>
<Grid Background="#FFE5E5E5" Width="0"/>
</Expander>
</Grid>
<Grid HorizontalAlignment="Stretch" Grid.Column="1" Grid.ColumnSpan="2" VerticalAlignment="Stretch" Height="Auto" Width="Auto" Margin="2,0,0,0.2">
<Grid Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="6" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,10.4,0.267,0.2" Background="{DynamicResource {x:Static SystemColors.AppWorkspaceBrushKey}}" />
</Grid>
</Grid>
I have 3 columns in my main grid. One is expander and other 2 are grid.
I want the other two columns to take up the space when expander is collapsed.

First, I think your GroupBox should be in your Expander. You need to fix your grid rows, because those are broken--there is no Grid.Row="3". You need to change the Width to Auto on your Grid in Column 0 in your MainGrid. There are probably other things that need attention, but this should help you get a start on figuring out what you need to do:
<Grid x:Name="MainGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="177*" />
<ColumnDefinition Width="133*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="680*" />
<RowDefinition Height="31*" />
</Grid.RowDefinitions>
<Grid Grid.Column="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="8*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Expander ExpandDirection="Right"
Grid.Column="0"
IsExpanded="True">
<Expander.Header>
<TextBlock Text="Header">
<TextBlock.LayoutTransform>
<RotateTransform Angle="90" />
</TextBlock.LayoutTransform>
</TextBlock>
</Expander.Header>
<GroupBox Name="groupBoxMain"
BorderBrush="Black"
Grid.Row="0"
Margin="0,0,0,6">
<DataGrid Background="DarkGray"
CanUserResizeColumns="True"
CanUserSortColumns="True">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding BackupVersionNumber}"
Header="File Name"
MinWidth="100"
FontFamily="Default Font"
FontSize="16" />
<DataGridTextColumn Binding="{Binding BackupDateTime}"
Header="Total Time"
MinWidth="100"
FontFamily="Default Font"
FontSize="16" />
<DataGridTextColumn Binding="{Binding SavedBy}"
Header="Total Packet"
MinWidth="100"
FontFamily="Default Font"
FontSize="16" />
</DataGrid.Columns>
</DataGrid>
</GroupBox>
</Expander>
</Grid>
<Grid Grid.Column="1"
Grid.ColumnSpan="2"
Height="Auto"
Width="Auto"
Margin="2,0,0,0.2">
<Grid Grid.Row="3"
Grid.Column="0"
Grid.ColumnSpan="6"
Margin="0,10.4,0.267,0.2"
Background="{DynamicResource {x:Static SystemColors.AppWorkspaceBrushKey}}" />
</Grid>
</Grid>

Related

I want textblock value but could not able to do that

<Grid>
<GroupBox FontSize="16" FontWeight="Bold" Header="Testing"
BorderBrush="Orange" BorderThickness="3">
<DataGrid Background="Transparent">
<DataGrid.Columns>
<DataGridTemplateColumn Width="Auto">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid IsEnabled="True" Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text="Hello" Width="50" HorizontalAlignment="Center" VerticalAlignment="Center"
ToolTipService.ToolTip="Testing" Background="Aqua" ToolTipService.IsEnabled="True"
ToolTipService.ShowOnDisabled="True" IsEnabled="True" Height="20" >
</TextBlock>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</GroupBox>
</Grid>
Here is my XAML and this datagrid also comes under groupbox . I have tried many approach but couldnt figure it out . I want to show textblock value.

Grid in Grid not showing Scrollbar in C# WPF

I have a Grid in another Grid and add the second Grid into ScrollViewer but don't see scrollbar for it. The grid i add ScrollViewer has the name InfoGrid. I dont understand why ScrollViewer is not working. Is there any alternative way you can suggest me ? My xaml code for the all window :
<Window x:Class="ModelView.KillCardCheck"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="Auto" Height="Auto" SizeToContent="WidthAndHeight"
ResizeMode="NoResize" Icon="pack://application:,,,/Resources/image/ffdc_gui.png"
xmlns:lex="http://schemas.root-project.org/xaml/presentation" Closing="WindowClosing">
<Grid Style="{DynamicResource GridStyle}" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="12"/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="11"/>
<ColumnDefinition Width="109"/>
<ColumnDefinition Width="250"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<DataGrid Grid.Column="1" Grid.ColumnSpan="3" Grid.Row="2" Style="{DynamicResource {x:Type DataGrid}}"
AutoGenerateColumns="False" CanUserSortColumns="False" CanUserAddRows="False"
Margin="4,4,4,4" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" RowHeight="25" Name="dgKillCardChecks"
SelectionMode="Single" BorderThickness="1,1,1,0">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Number}"
Width="30" IsReadOnly="True">
</DataGridTextColumn>
<DataGridTemplateColumn Header="{lex:LocText Key=check_list, Dict=language, Assembly=FfdcLocalization}" Width="*" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Name="chkCheckList" Content="{Binding CheckItem}"
Click="CheckListCheckBoxOnClick"
Tag="{Binding Index}"
IsChecked="{Binding Path=CheckStatus, UpdateSourceTrigger=PropertyChanged}"
IsHitTestVisible="{Binding Enabled}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
<ScrollViewer VerticalScrollBarVisibility="Visible">
<Grid Style="{DynamicResource GridStyle}" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="3" Margin="4,4,4,4" Name="InfoGrid" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
</Grid>
</ScrollViewer>
<TextBlock Name="descriptionBlock" TextWrapping="Wrap" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" Margin="4,4,4,4"></TextBlock>
<Button Style="{DynamicResource {x:Type Button}}" Grid.Row="4" Grid.Column="3" Grid.ColumnSpan="1"
x:Name="btnQuit" MaxHeight="30" Margin="2,4,0,6" MaxWidth="120" MinWidth="80"
Content="{lex:LocText Key=close, Dict=language, Assembly=FfdcLocalization}"
VerticalContentAlignment="Center" MinHeight="30" VerticalAlignment="Center" HorizontalAlignment="Left" Click="CloseClick"/>
<Button Style="{DynamicResource {x:Type Button}}" Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2"
x:Name="btnClear" MaxHeight="30" Margin="2,4,0,6" MaxWidth="200" MinWidth="80"
Content="{lex:LocText Key=clear_killcard, Dict=language, Assembly=FfdcLocalization}"
VerticalContentAlignment="Center" MinHeight="30" VerticalAlignment="Center" HorizontalAlignment="Right" Click="ClearKillCardClick"/>
</Grid>
</Window>
The ScrollViewer that you made has no grid.Row set, instead you put it on the grid inside it. That does not make much sense since the grid ("Info Grid") is inside the ScrollViewer so it's parent is the ScrollViewer. You might want to try setting the ScrollViewer row and column.

how to correct columns and rows that nicely displays datagrid?

I am working on some view in wpf mvvm. I don't know how to fix columns and rows to show correctly my datagrid. I want to have one textbox under name, one textbox under value
Here is a image and xaml code, can anybody help me?
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<DataGrid ItemsSource="{Binding EnviromentVariables}" IsReadOnly="False" Margin="10" AutoGenerateColumns="False" Grid.ColumnSpan="4">
<DataGrid.Columns>
<DataGridTextColumn x:Name="name" Width="*" Header="Name" Binding="{Binding Name}" />
<DataGridTextColumn x:Name="value" Width="*" Header="Value" Binding="{Binding Value}" />
</DataGrid.Columns>
</DataGrid>
<StackPanel Orientation="Horizontal" Grid.Row="1">
<TextBox Grid.Row="1" Grid.Column="1" Width="{Binding ElementName =name}" />
<TextBox Grid.Row="1" Grid.Column="3" Width="{Binding ElementName= value}"/>
<Button Content="+" Grid.Column="2" Grid.Row="2" />
<Button Content="-" Grid.Column="3" Grid.Row="2" />
</StackPanel>
</Grid>
Try first of all removing the StackPanel, because, even if you use Grid.Row and Grid.Column properties nothing will effect:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<DataGrid ItemsSource="{Binding EnviromentVariables}" IsReadOnly="False" Margin="10" AutoGenerateColumns="False" Grid.ColumnSpan="4">
<DataGrid.Columns>
<DataGridTextColumn x:Name="name" Width="*" Header="Name" Binding="{Binding Name}" />
<DataGridTextColumn x:Name="value" Width="*" Header="Value" Binding="{Binding Value}" />
</DataGrid.Columns>
</DataGrid>
<TextBox Grid.Row="1" Grid.Column="0" Width="{Binding ElementName =name}" Grid.ColumnSpan="2" Margin="10,0,0,0"/>
<TextBox Grid.Row="1" Grid.Column="2" Width="{Binding ElementName= value}" Grid.ColumnSpan="2" Margin="0,0,10,0"/>
<Button Content="+" Grid.Column="2" Grid.Row="2" />
<Button Content="-" Grid.Column="3" Grid.Row="2" />
</Grid>
Remember to adjust margin of Textboxes.

ContentControl inside TabItem doesn't resize proberly

I have a ContentControl inside a TabItem. The ContentControl displays a UserControl. My Problem is the Width of the ContentControl isn't set corectly, it is way to big. The Height is correctly displayd.
I want to SizeToContent because I have multiple TabItems with different sizes.
I have the following code:
MainWindow.xaml (Short Version)
<Window Height="350" Width="525" SizeToContent="WidthAndHeight">
<DockPanel>
<TabControl DockPanel.Dock="Left" TabStripPlacement="Left">
<TabItem Header="BDE Config" IsEnabled="{Binding LoggedIn}">
<Grid>
<ContentControl Content="{Binding CurrentViewModel}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
</Grid>
</TabItem>
</TabControl>
</DockPanel>
The UserControl doesn't has Width/Height Properties. So why is it that the Height is correct but the Width way to big for my Screen.
XAML of the UserControl:
<UserControl x:Class="BDE_Config2015.Views.BDEConfig"
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:local="clr-namespace:BDE_Config2015"
xmlns:h="clr-namespace:BDE_Config2015.Helpers"
mc:Ignorable="d"
Background="{StaticResource AppBg}" d:DesignHeight="655" d:DesignWidth="1180">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<!--1-->
<GroupBox Grid.Column="0" Grid.Row="0" Header="BDE-Benutzer">
<ComboBox Height="23" DisplayMemberPath="Benutzername" SelectedValuePath="Kbez" ItemsSource="{Binding BDEConfigModel.BDEBenutzer}" SelectedValue="{Binding CurrentUser}" />
</GroupBox>
<!--2-->
<TabControl Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" Background="Transparent" Margin="0,3,0,0">
<TabItem Header="BDE">
<Grid x:Name="gBDEKonfig">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition />
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"/>
<ColumnDefinition Width="80"/>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="70"/>
<ColumnDefinition Width="80"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<!--Row 0-->
<TextBlock Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" Text="Buttons pro Reiter" VerticalAlignment="Center" Visibility="Collapsed" />
<TextBox Grid.Column="2" Grid.Row="0" Name="txtBDEReiter" Margin="0,0,0,5" Visibility="Collapsed" />
<TextBlock Grid.Column="3" Grid.Row="0" Text="Hintergrundfarbe" VerticalAlignment="Center" Margin="10,0,0,0" Visibility="Collapsed" />
<TextBox Grid.Column="4" Grid.Row="0" Margin="0,0,0,5" Visibility="Collapsed" />
<Button Grid.Column="5" Grid.Row="0" Margin="10,0,0,5" Visibility="Collapsed">...</Button>
<!--Row 1-->
<TextBlock Grid.Column="0" Grid.Row="1" Text="BDE-Titel" VerticalAlignment="Top"/>
<TextBox Grid.Column="1" Grid.ColumnSpan="3" Grid.Row="1" Margin="0,0,0,5" Text="{Binding BDETitel, UpdateSourceTrigger=LostFocus}" KeyDown="TextBox_KeyDown" />
<!--Row 2-->
<TextBlock Grid.Column="0" Grid.Row="2" Text="BDE-Belegung"/>
<!--Row 3-->
<DataGrid Grid.Column="0" Grid.ColumnSpan="8" Grid.Row="3" ItemsSource="{Binding BDEConfigModel.Clientoptionen}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserReorderColumns="False"
SelectedValue="{Binding crBDEBelegung}" Name="dgvBDEBelegung" CellEditEnding="DGV_CellEditEnding" CurrentCellChanged="DGV_CurrentCellChanged"
h:DataGridBehavior.AutoScrollIntoView="True" SelectionMode="Single">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Nummer, UpdateSourceTrigger=LostFocus}" Header="Nr" />
<DataGridTextColumn Binding="{Binding OptionText, UpdateSourceTrigger=LostFocus}" Header="Arbeitsplatztitel" />
<DataGridTextColumn Binding="{Binding OptionInfo, UpdateSourceTrigger=LostFocus}" Header="Buttonbezeichnung"/>
<DataGridTemplateColumn Header="Anlage" Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox DisplayMemberPath="Anlage" SelectedValuePath="FertigungsStättenID" SelectedValue="{Binding OptionZahl}" IsTextSearchEnabled="True"
ItemsSource="{Binding Path=DataContext.BDEConfigModel.Fertigungsstaette, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
SelectedItem="{Binding Path=DataContext.siFertigungsstaette, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Mode=OneWayToSource}">
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Arbeitsplatz" Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox DisplayMemberPath="Arbeitsplatzbez" SelectedValuePath="ArbeitsPlatzNummer" SelectedValue="{Binding OptionGanzzahl}" IsTextSearchEnabled="True"
ItemsSource="{Binding Path=DataContext.BDEConfigModel.Arbeitsplatz, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
SelectedItem="{Binding Path=DataContext.siArbeitsplatz, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Mode=OneWayToSource}">
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
<!--Row 4-->
<Button Grid.Column="0" Grid.Row="4" Margin="5" Command="{Binding NeuBDEBelegungCommand}">Neu</Button>
<Button Grid.Column="1" Grid.Row="4" Margin="5" Command="{Binding LoeschenBDEBelegungCommand}">Löschen</Button>
</Grid>
</TabItem>
<TabItem Header="Arbeitsgang/Arbeitsplan">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*"/>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="Arbeitsplan"/>
<DataGrid Grid.Row="1">
</DataGrid>
<CheckBox Grid.Row="2" HorizontalAlignment="Right" Content="Unabhängig vom Arbeitsplan" Margin="0,10,5,0" />
<TextBlock Grid.Row="3" Text="Arbeitsgang"/>
<DataGrid Grid.Row="4">
</DataGrid>
</Grid>
</TabItem>
<TabItem Header="ColumnsManagement">
<Grid Margin="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="Arbeitsplatz" Margin="5,0" />
<ComboBox Grid.Column="1" Margin="5,0,5,5" ItemsSource="{Binding BDEConfigModel.BDEArbeitsplatz}" DisplayMemberPath="OptionText" SelectedValuePath="PKID"
SelectedValue="{Binding SelectedArbeitsplatzCM}" />
<TextBlock Grid.Column="2" Text="DataSource" Margin="5,0" />
<ComboBox Grid.Column="3" Margin="5,0,5,5" SelectedValue="{Binding SelectedDataSource}">
<ComboBox.ItemsSource>
<x:Array Type="sys:String" xmlns:sys="clr-namespace:System;assembly=mscorlib">
<sys:String>proc_BDEoW_ChargeStartDetail</sys:String>
<sys:String>proc_BDEoW_ChargeProduktion</sys:String>
</x:Array>
</ComboBox.ItemsSource>
</ComboBox>
<Button Grid.Column="4" Content="Laden" Width="85" HorizontalAlignment="Right" Margin="5,0,5,5" Command="{Binding LadenCMCommand}"/>
</Grid>
<DataGrid Grid.Row="1" ItemsSource="{Binding BDEConfigModel.ArbeitsplatzSpaltenManagement}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserReorderColumns="False"
IsEnabled="{Binding EnabledCM}" SelectedValue="{Binding crArbeitsplatzSM}" h:DataGridBehavior.AutoScrollIntoView="True">
<DataGrid.Columns>
<DataGridTextColumn Width="Auto" Header="Spalte" Binding="{Binding SQLVisibleColumns}" />
<DataGridTextColumn Width="*" Header="Titel" Binding="{Binding SQLVisibleColumnsName}" />
<DataGridTextColumn Width="*" Header="%Weite" Binding="{Binding SQLVisibleColumnsWidth}" />
<DataGridTextColumn Width="*" Header="ReadOnly" Binding="{Binding SQLVisibleColumnsAccess}" />
</DataGrid.Columns>
</DataGrid>
<TextBlock Grid.Row="2" Text="{Binding MessageCM}" HorizontalAlignment="Stretch" Margin="5,0,5,0" />
<Grid Grid.Row="3">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Content="Neu" Margin="5" Command="{Binding NeuCMCommand}" IsEnabled="{Binding EnabledCM}" />
<Button Grid.Column="1" Content="Löschen" Margin="5" Command="{Binding LoeschenCMCommand}" IsEnabled="{Binding EnabledCM}" />
<Button Grid.Column="2" Content="Con. Kopieren" Margin="5" Command="{Binding KopierenCMCommand}" IsEnabled="{Binding EnabledCM}" />
<TextBox Grid.Column="3" IsReadOnly="True" Margin="5" Text="{Binding SummeCM}"/>
<Button Grid.Column="4" Content="Speichern" Margin="5" Command="{Binding SpeichernCMCommand}" IsEnabled="{Binding EnabledCM}" />
</Grid>
</Grid>
</TabItem>
</TabControl>
<!--3-->
<GroupBox Grid.Column="2" Grid.Row="0" Grid.RowSpan="2" Header="Modul-Info" Name="gbModulInfo" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"/>
<ColumnDefinition />
<ColumnDefinition Width="80"/>
</Grid.ColumnDefinitions>
<DataGrid Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="0" ItemsSource="{Binding BDEConfigModel.BDEModul}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserReorderColumns="False"
SelectedValue="{Binding crModulInfo}" h:DataGridBehavior.AutoScrollIntoView="True">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Typ}" Header="Typ" IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Bezeichnung}" Header="Bezeichnung" Width="*" IsReadOnly="True" />
</DataGrid.Columns>
</DataGrid>
<Button Grid.Column="0" Grid.Row="1" Content="V Spez." Margin="5" Command="{Binding VSpezCommand}"/>
<Button Grid.Column="2" Grid.Row="1" Content="V Global" Margin="5" Command="{Binding VGlobalCommand}"/>
</Grid>
</GroupBox>
<!--4-->
<GroupBox Grid.Column="0" Grid.Row="2" Header="Register" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid Name="gRegister">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"/>
<ColumnDefinition Width="80"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<DataGrid Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="0" ItemsSource="{Binding BDEConfigModel.Register}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserReorderColumns="False"
SelectedValue="{Binding crRegister}" h:DataGridBehavior.AutoScrollIntoView="True" CellEditEnding="DGV_CellEditEnding" CurrentCellChanged="DGV_CurrentCellChanged">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Nummer, UpdateSourceTrigger=LostFocus}" Header="Nr" IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding OptionText, UpdateSourceTrigger=LostFocus}" Header="Registername" Width="*"/>
</DataGrid.Columns>
</DataGrid>
<Button Grid.Column="0" Grid.Row="1" Content="Neu" Margin="5" Command="{Binding NeuRegisterCommand}" />
<Button Grid.Column="1" Grid.Row="1" Content="Löschen" Margin="5" Command="{Binding LoeschenRegisterCommand}" />
</Grid>
</GroupBox>
<!--5-->
<GroupBox Grid.Column="1" Grid.Row="3" Header="Spez. Modulzuordnung" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<DataGrid Name="dgvMZ" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" ItemsSource="{Binding BDEConfigModel.BDEMZ}" AutoGenerateColumns="False" CanUserAddRows="False"
CanUserReorderColumns="False" SelectedValue="{Binding crMZ}" h:DataGridBehavior.AutoScrollIntoView="True" CellEditEnding="DGV_CellEditEnding" CurrentCellChanged="DGV_CurrentCellChanged">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Modul}" Header="Typ" IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Modullevel, UpdateSourceTrigger=LostFocus}" Header="Level" />
<DataGridTextColumn Binding="{Binding Parameter1, UpdateSourceTrigger=LostFocus}" Header="Parameter" Width="*" />
<DataGridTextColumn Binding="{Binding ModulSetup, UpdateSourceTrigger=LostFocus}" Header="Setup" Width="*"/>
</DataGrid.Columns>
</DataGrid>
<Button Grid.Column="0" Grid.Row="1" Content="Löschen" Margin="5" Command="{Binding LoeschenMZCommand}"/>
</Grid>
</GroupBox>
<!--6-->
<GroupBox Grid.Column="2" Grid.Row="3" Header="Global Modulzuordnung" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<DataGrid Name="dgvMZGlobal" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" ItemsSource="{Binding BDEConfigModel.BDEMZGlobal}" AutoGenerateColumns="False" CanUserAddRows="False"
CanUserReorderColumns="False" SelectedValue="{Binding crMZGlobal}" h:DataGridBehavior.AutoScrollIntoView="True" CellEditEnding="DGV_CellEditEnding"
CurrentCellChanged="DGV_CurrentCellChanged">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Modul}" Header="Typ" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding Modullevel, UpdateSourceTrigger=LostFocus}" Header="Level"/>
<DataGridTextColumn Binding="{Binding Parameter1, UpdateSourceTrigger=LostFocus}" Header="Parameter" Width="*"/>
<DataGridTextColumn Binding="{Binding ModulSetup, UpdateSourceTrigger=LostFocus}" Header="Setup" Width="*"/>
</DataGrid.Columns>
</DataGrid>
<Button Grid.Column="0" Grid.Row="1" Content="Löschen" Margin="5" Command="{Binding LoeschenMZGlobalCommand}"/>
</Grid>
</GroupBox>
</Grid>
It seems to be related to a strange interaction between the SizeToContent property on the window and the "star-sizing" on the data grid columns.
Either set the window's SizeToContent property to Height and explicitly set a width for the window, or limit the width of the star-sized columns by setting their MaxWidth properties to some suitable limit.
This thread on CodePlex describes the problem. Apparently things used to be worse in that an exception would be thrown! From a post at the very bottom of that thread:
The exception has been fixed but it's still not working properly. When placed in a user control with (sic) doesn't have a fixed width, setting "*" on column width will cause the column to be extremely wide (several thousand pixel), and this happens both at design time and run time.
As an aside, you could get rid of a lot of XAML markup by using StackPanel and DockPanel containers rather than using a Grid for everything.
After some more trying I have found an Answert that works for me. I have done the following:
MaxWidth="{x:Static SystemParameters.PrimaryScreenWidth}" WindowStartupLocation="CenterScreen" Left="{Binding winLeft, Mode=TwoWay}" Top="{Binding winTop, Mode=TwoWay}"
It sets the MaxWidth of the Window the the Screen Width and then whenever a User Control with Star-Sized Columns is loaded it also sets the Position to 0,0.

GridSplitter with DataGrid as left hand side component

I have a problem with resizing a column that contains a DataGrid. When I create more space for the column that contains the DataGrid, the DataGrid actually shrinks in Width.
Tried to google for a solution, but found nothing useful so far.
XAML:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="45"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.7*"/>
<ColumnDefinition Width="5"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="130"/>
</Grid.ColumnDefinitions>
<DataGrid
x:Name="DowloadedEpisodesDataGrid"
ItemsSource="{Binding DownloadedEpisodes, Mode=OneWay, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}"
Grid.Column="0"
AutoGenerateColumns="False"
Background="White">
<DataGrid.Columns>
<DataGridCheckBoxColumn Width="50" Header="Import" Binding="{Binding IsSelected}" />
<DataGridTextColumn Width="Auto" Header="Downloaded episode" IsReadOnly="True" Binding="{Binding FileName}"/>
</DataGrid.Columns>
</DataGrid>
<GridSplitter Grid.Column="1" Width="5" Visibility="Visible" ResizeDirection="Columns" VerticalAlignment="Stretch" />
<views:EpisodeDetailsUserControl
x:Name="EpisodeDetailsUserControl"
DataContext="{Binding ElementName=DowloadedEpisodesDataGrid, Path=SelectedItem}"
Grid.Column="2"
Grid.ColumnSpan="2"/>
Before resizing:
After resizing:
I'd like to understand WHY the default behavior is to shrink the DataGrid and of course I'd like very much to deal with the problem.
Many thanks in advance.
You need to set HorizontalAlignment to Stretch on GridSplitter -
<GridSplitter Grid.Column="1"
ResizeDirection="Columns"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch" />

Categories

Resources