带有Windows Phone 8.1应用程序右侧列的ListView

时间:2015-05-08 04:33:56

标签: windows-phone-8.1 winrt-xaml

我有一个ListView的问题,我不知道如何解决它没有硬编码宽度:

我有这个listView:

<ListView 
        Name="lstStates"
        CommonNavigationTransitionInfo.IsStaggerElement="True" 
        ContinuumNavigationTransitionInfo.ExitElementContainer="True" 
        IsItemClickEnabled="True"
        ItemClick="lstStates_ItemClick"
        ItemsSource="{Binding States}"
        HorizontalAlignment="Stretch"
        >
        <ListView.ItemTemplate>
            <DataTemplate>
                <Grid Margin="8" Background="AliceBlue" HorizontalAlignment="Stretch">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="1*" />
                        <ColumnDefinition Width="auto" />
                    </Grid.ColumnDefinitions>
                    <TextBlock 
                        CommonNavigationTransitionInfo.IsStaggerElement="True"
                        Style="{ThemeResource ListViewItemTextBlockStyle}"
                        Text="{Binding State, FallbackValue=State}"/>
                    <TextBlock
                        Grid.Column="1"
                        Style="{ThemeResource ListViewItemTextBlockStyle}"
                        Text="{Binding Count, FallbackValue=1}"/>
                </Grid>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

正如你所看到的,基本上是如何在右边计数(与计数绑定的文本块)。问题是每个网格只使用它需要的宽度而不是获得整个空间

想法?

由于

1 个答案:

答案 0 :(得分:0)

请尝试以下操作:

<ListView></ListView>标记内添加以下内容:

<ListView.ItemContainerStyle>
  <Style TargetType="ListViewItem">
     <Setter Property="HorizontalContentAlignment" Value="Stretch" />
  </Style>
</ListView.ItemContainerStyle>