我有一个使用以下模板的 ListBox:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="64" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
<Image Source="{Binding Property3}" Grid.Column="0" HorizontalAlignment="Left" Height="64" Width="64"/>
<TextBlock Grid.Column="1" Text="{Binding Property1}"/>
<TextBlock Grid.Column="2" Text="{Binding Property2}" HorizontalAlignment="Right"/>
</Grid>
我遇到的问题是中间栏。中间列中文本的长度决定了网格的宽度。在不使用确切的宽度值的情况下使网格扩展到页面宽度的 100% 的最佳方法是什么?或者这是不可能的?我从这里尝试了很多建议(例如,在 ListBox 上设置 HorizontalContentAlignment)无济于事。
编辑:这是整页,突出问题的最少代码:
<phone:PhoneApplicationPage
x:Class="FoursquareDemo.SandboxPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True">
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="ItemTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="64" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
<Image Source="{Binding Property3}" Grid.Column="0" HorizontalAlignment="Left" Height="64" Width="64"/>
<TextBlock Grid.Column="1" Text="{Binding Property1}"/>
<TextBlock Grid.Column="2" Text="{Binding Property2}" HorizontalAlignment="Right"/>
</Grid>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
<ListBox x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource SampleDataSource}}" ItemTemplate="{StaticResource ItemTemplate}" ItemsSource="{Binding Collection}" />