Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
573 views
in Technique[技术] by (71.8m points)

windows 8 - ListViewItem won't stretch to the width of a ListView

I'm currently designing a windows 8 store app using XAML but I have a minor sizing issue. I have a ListView with a DataTemple.

The code for my ListView & DataTemplate are below:

<ListView x:Name="listPageItems"
          Grid.Row="1"
          SelectionMode="Extended"
          IsSwipeEnabled="False"
          ItemsSource="{Binding Mode=OneWay, Source={StaticResource items}}"
          ItemTemplate="{StaticResource NavigationItemTemplate}"
          ScrollViewer.VerticalScrollBarVisibility="Visible">

</ListView>

<DataTemplate x:Key="NavigationItemTemplate">    
        <Grid Height="75">
            <Grid.RowDefinitions>
                <RowDefinition Height="1.6*" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Rectangle Fill="White" />
            <Rectangle Fill="{StaticResource SSEGreenBrush}"
                       Grid.Row="1" />
            <Border BorderThickness="2"
                    BorderBrush="{StaticResource SSEGreenBrush}"
                    Grid.RowSpan="2" />
            <TextBlock x:Name="textTitle"
                       Text="{Binding ClientName}"
                       Style="{StaticResource TitleTextStyle}"
                       Foreground="{StaticResource SSEBlueBrush}"
                       Margin="10,5,5,5" />
            <StackPanel Orientation="Horizontal"
                        Grid.Row="1"
                        HorizontalAlignment="Stretch">
                <TextBlock Text="Last Edit :"
                           Style="{StaticResource SubtitleTextStyle}"
                           Foreground="{StaticResource SSEBlueBrush}"
                           Margin="3,0,0,3"
                           VerticalAlignment="Center" />
                <TextBlock Text="SurveyDate"
                           Style="{StaticResource SubtitleTextStyle}"
                           Foreground="{StaticResource SSEBlueBrush}"
                           Margin="3,0,0,3"
                           VerticalAlignment="Center" />
            </StackPanel>
        </Grid>
    </DataTemplate>

The listview is within a grid column with a fixed width of 240.

When the view is displayed the ListViewItems don't stretch to the width of the ListView. I've tried setting numerous properties including the HorizontalContentAlignment but I can't seem to get the ListViewItem to stretch!

Can anybody help?

Thanks in advance.

I'm using Visual studio 2012, C# 4.5 and developing a Windows store app.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try adding the following to your ListView definition

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...