How do I make a control fill the whole cell in a ListView (with a GridView)? I\'ve played around with various properties, but the control is always it\'s minimum size.
Your user control specifies the values for the "Height" and "Width" properties. Nothing is allowed to override properties you have explicitly set. Remove "Height" and "Width" and the control's container will be able to mess with the size.
You might want to set a reasonable "MinHeight" and "MinWidth" to prevent containers from squishing you.
Different containers do different things to your control's size; for example, Grid expands you to fill the grid cell you're in, while StackPanel shrinks you to your minimum size. So you might need to deal with that too.
After narrowing down my question I was about to Google and find an answer here.
Basically for some reason the ListViewItems are set to align to the Left. Setting them to Stretch fixes this problem. This is done through a style like so:
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
This unfortunately affects every column, but then you can set the contents of other columns to left, right, center as explained in the link.
Another almost-solution is to do something as follows in your datatemplate that goes into the gridviewcolumn
Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor , AncestorType=ListViewItem, AncestorLevel=1},Path=ActualWidth}">
This results in it stretching the textbox to the width of the column, but the right edge is clipped and not rendered. I haven't fixed that part yet. So the already accepted answer is still probably the best one.
Here's a sample DataTemplate which does this.
<DataTemplate DataType="{x:Type local:EditableStringElement}"
x:Key="cellSalutation">
<TextBox Text="{Binding _RecipientData._Salutation.Value , Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsEnabled="{Binding _RecipientData._Salutation.IsEnabled}"
Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor , AncestorType=ListViewItem, AncestorLevel=1},Path=ActualWidth}">
</TextBox>