I have a fairly complex financial report with a number of headers and summarizing footers and with tabular data inbetween. Here is what is supposed to look like:
The topmost container of the page is a Grid whose columns should automatically adjust when the page is resized. In this Grid all headers and summary fields are contained. Inbetween is a DataGrid that is supposed to hold the detailed financial data and of course I need to have the column width of it's columns the same size as those of the Grid. My problem is that I am not able to bind the width of the DataGrid columns to the width of the enclosing DataGrid. Here is the code:
<Grid x:Name="gridKonsolidiert"
Grid.Row="1"
HorizontalAlignment="Stretch"
Margin="0,0,9,0">
<Grid.RowDefinitions>
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="22" />
<RowDefinition Height="*" />
<RowDefinition Height="22" />
....
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="gcolEADatum" Width="50*" />
<ColumnDefinition x:Name="gcolEinBtto20" Width="60*" />
<ColumnDefinition x:Name="gcolEinUSt20" Width="60*" />
<ColumnDefinition x:Name="gcolEinNtto20" Width="60*" />
....
</Grid.ColumnDefinitions>
<DataGrid x:Name="dgvKonsolidiert"
Grid.Row="3"
Grid.Column="0"
Grid.ColumnSpan="21"
Focusable="True"
Width="{Binding ElementName=gridKonsolidiert, Path=ActualWidth}"
ItemsSource="{Binding KonsolidiertCol, Mode=OneWay}"
IsSynchronizedWithCurrentItem="True"
AlternationCount="2"
AlternatingRowBackground="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"
SelectionMode="Single"
SelectionUnit="FullRow"
AutoGenerateColumns="False"
GridLinesVisibility="None"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
RenderTransformOrigin="0.5,0.5"
CanUserAddRows="False"
HeadersVisibility="Column"
VerticalScrollBarVisibility="Hidden"
HorizontalScrollBarVisibility="Disabled"
CanUserReorderColumns="False"
CanUserResizeColumns="False"
CanUserResizeRows="False"
RowDetailsVisibilityMode="Visible"
BorderThickness="1"
BorderBrush="{StaticResource DataGridBorderColor}"
IsReadOnly="True"
Margin="0,2,0,20"
Grid.RowSpan="2">
<DataGrid.Columns>
<DataGridTextColumn x:Name="colEADatum"
Header="Datum"
HeaderStyle="{StaticResource DataGridHeaderCentered_BorderRight}"
CellStyle="{StaticResource DataGridCellCentered_BorderRight}"
Width="{Binding ElementName=gcolEADatum, Path=ActualWidth, diag:PresentationTraceSources.TraceLevel=High}"
Binding="{Binding Path=EADatum, StringFormat=dd.MM}"
TextBlock.LineHeight="24">
</DataGridTextColumn>
<DataGridTextColumn x:Name="colEinBtto20"
Header="Brutto"
HeaderStyle="{StaticResource DataGridHeaderRightAligned}"
Width="60*"
CellStyle="{StaticResource DataGridCellRightAligned}"
Binding="{Binding Path=EinBtto20, StringFormat={StaticResource fmtNumberOrEmpty}}">
</DataGridTextColumn>
<DataGridTextColumn x:Name="colEinUSt20"
Header="USt"
HeaderStyle="{StaticResource DataGridHeaderRightAligned}"
Width="60*"
CellStyle="{StaticResource DataGridCellRightAligned}"
Binding="{Binding Path=EinUSt20, StringFormat={StaticResource fmtNumberOrEmpty}}">
</DataGridTextColumn>
....
</DataGrid.Columns>
</DataGrid>
The diagnose in Output Window then states:
System.Windows.Data Warning: 56 : Created BindingExpression (hash=58206383) for Binding (hash=58663159)
System.Windows.Data Warning: 58 : Path: 'ActualWidth'
System.Windows.Data Warning: 60 : BindingExpression (hash=58206383): Default mode resolved to OneWay
System.Windows.Data Warning: 61 : BindingExpression (hash=58206383): Default update trigger resolved to PropertyChanged
System.Windows.Data Warning: 62 : BindingExpression (hash=58206383): Attach to System.Windows.Controls.DataGridTextColumn.Width (hash=48266778)
System.Windows.Data Warning: 64 : BindingExpression (hash=58206383): Use Framework mentor <null>
System.Windows.Data Warning: 67 : BindingExpression (hash=58206383): Resolving source
System.Windows.Data Warning: 69 : BindingExpression (hash=58206383): Framework mentor not found
System.Windows.Data Warning: 65 : BindingExpression (hash=58206383): Resolve source deferred
'EARechnung_C.exe' (CLR v4.0.30319: EARechnung_C.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework.resources\v4.0_4.0.0.0_de_31bf3856ad364e35\PresentationFramework.resources.dll'. Module was built without symbols.
System.Windows.Data Warning: 67 : BindingExpression (hash=58206383): Resolving source
System.Windows.Data Warning: 69 : BindingExpression (hash=58206383): Framework mentor not found
'EARechnung_C.exe' (CLR v4.0.30319: EARechnung_C.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Resources.ResourceManager\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Resources.ResourceManager.dll'. Cannot find or open the PDB file.
System.Windows.Data Warning: 79 : BindingExpression (hash=58206383): Deactivate
System.Windows.Data Warning: 63 : BindingExpression (hash=58206383): Detach
I hope there is anybody that can help me with that problem.