I'm having an issue forcing the width of a text column to take up 100% of its remaining space. The DataGrid itself is nested within a ListView, which is further nested in a ListView. It's data binding is an observablelist of obvservablelists, filled with strings of varying lengths.
I'm building in VS 2012, WPF 4.5, with the MVVM-Light toolkit to help with coupling, etc.
The column I'd like to take up 100% of remaining space is the second column (PropertyValue). I've tried a few different things including:
Code is below:
<UserControl x:Class="Foo.Views.XXLViews.XXLInformationView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ignore="http://www.ignore.com"
mc:Ignorable="d ignore"
DataContext="{Binding XXLInformationViewModel, Source={StaticResource Locator}}">
<Grid>
<Grid Margin="25,10,0,0" HorizontalAlignment="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical" Grid.Column="0">
<ListView ItemsSource="{Binding UnknownPropertiesCollections}" BorderThickness="0" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Padding="-4,2,0,0" Name="ListOfProperties">
<ListView.ItemTemplate>
<DataTemplate>
<ListView ItemsSource="{Binding}" BorderThickness="0" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Padding="-8,2,0,0">
<TextBlock Text="{Binding Name}" Style="{StaticResource PropertyListHeader}"/>
<DataGrid ItemsSource="{Binding PropertyCollection}" AutoGenerateColumns="False" Width="Auto">
<DataGrid.Columns>
<DataGridTextColumn Width="Auto" Binding="{Binding Path=PropertyName}" FontWeight="Bold">
</DataGridTextColumn>
<DataGridTextColumn Width="{Binding Path=ActualWidth, ElementName=ListOfProperties}" Binding="{Binding Path=PropertyValue}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="HorizontalAlignment" Value="Center"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</ListView>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackPanel>
</Grid>
</Grid>
A screen snip of what I am seeing:
I've spent a bit more time than I expected on this, so hoping that someone can give me a clue as to what the issue is. (And I'll be moving the inline styles for those listviews into a global style once everything is finalized).
I changed HorizontalContentAlignment="Stretch"
to HorizontalContentAlignment="Center"
This made the DataGrid only as wide as needed. This was good enough for my situation.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.