Reputation: 147
I am trying to assign the width of each of the DataGridTemplateColumn in a DataGrid using "*".
<DataGrid Name="Mapping" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="1"
ItemsSource="{Binding Information.Signals}"
SelectionMode="Single" AutoGenerateColumns="False" VirtualizingPanel.IsVirtualizing="True" FontSize="10"
RowDetailsVisibilityMode="VisibleWhenSelected" BorderThickness="1"
EnableColumnVirtualization="True" EnableRowVirtualization="True" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.IsDeferredScrollingEnabled="True"
ScrollViewer.CanContentScroll ="True" VirtualizingPanel.VirtualizationMode="Recycling"
CanUserAddRows="True" CanUserResizeRows="False" CanUserDeleteRows="True" SelectionUnit="FullRow"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
>
<DataGrid.Columns>
<DataGridTemplateColumn Header="Name"
CellTemplate="{StaticResource NameTemplate}"
CanUserSort="True" CanUserReorder="False" CanUserResize="True" SortMemberPath="Name"
Width="6*"
>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Type"
CellTemplate="{StaticResource PropertyTemplate}"
CanUserSort="True" CanUserReorder="False" CanUserResize="True" SortMemberPath="SelectedProperty"
Width="4*">
</DataGridTemplateColumn>
And the ColumnTemplates are similar to this one
<DataTemplate x:Key="NameTemplate">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Center">
<TextBlock Text="{Binding Path=Name}" MinWidth="280" FontSize="11" FontFamily="Calibri"
HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
</Grid>
</DataTemplate>
When the Window is Maximized the scaling works fine. What happens is that when it is not Maximized, the Header is almost 3 Monitors wide, like 3000 pixels.
If I set the width to a fixed value everything is fine as well. Could anyone suggest me how to tackle this problem? I would like to use the relative scaling using "*"
UPDATE: The WPF Project is using MahApps controls, so I am not sure if this is the reason.
Upvotes: 2
Views: 1773
Reputation: 943
Width and Height when applied using "*" are measured on count of "1". So whenever you divide your screen it has to be divided such as one full part is being divided.
Using 4* and 6* is incorrect. Use 0.4* and 0.6* instead, which sums to one.
Upvotes: 1