Reputation: 434
The ListViewItems are getting their width from the TextBlock element. I want the ListViewItem to fit to the ListView. I have seen in other posts that making HorizontalContentAlignment="Stretch"
will fix the issue, but my problem persists. The second TextBlock element in the ItemTemplate is set to WrapWithOverflow
.
Sources:
Code:
<UserControl x:Class="XXXX.Views.XXXXView"
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:cal="http://www.caliburnproject.org"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Background="{StaticResource BlackBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20*"/>
<ColumnDefinition Width="32*"/>
<ColumnDefinition Width="6*"/>
<ColumnDefinition Width="32*"/>
</Grid.ColumnDefinitions>
<DockPanel Grid.Column="1">
<ListView Grid.Column="1"
x:Name="UniqueShortDescriptions"
VerticalAlignment="Stretch"
ItemsSource="{Binding UniqueShortDescriptions}"
SelectedItem="{Binding SelectedUniqueShortDescriptions}"
cal:Message.Attach="[Event SelectionChanged] = [Action SelectionChanged($this, $eventArgs)]">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Navy"
BorderThickness="3"
Margin="3"
Padding="2">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Grid.RowSpan="3"
Grid.Column="0"
Text="{Binding Path=Date}"
Foreground="Black"
VerticalAlignment="Center"
TextBlock.FontWeight="ExtraBold"/>
<TextBlock Grid.Row="0"
Grid.Column="1"
Text="{Binding Path=LongDescription}" Foreground="{StaticResource BlackBrush}"
TextWrapping="WrapWithOverflow"/>
<!--<TextBlock Text="{Binding Path=ShortExpenseDescription}" Foreground="{StaticResource BlackBrush}"/>-->
<TextBlock Grid.Row="1"
Grid.Column="1"
Text="{Binding Path=Cost}" Foreground="{StaticResource BlackBrush}"/>
<TextBlock Grid.Row="2"
Grid.Column="1"
Text="{Binding Path=Source}" Foreground="{StaticResource BlackBrush}"/>
</Grid>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</DockPanel>
</Grid>
</UserControl>
Upvotes: 2
Views: 1612
Reputation: 319
I got the code you posted to work by simply disabling horizontal scrolling of the ListView.
<ListView ScrollViewer.HorizontalScrollBarVisibility="Disabled" ...
Upvotes: 2