UWP网格中的内部项目未拉伸XAML

Til*_*cey 4 wpf xaml uwp

此列表视图中的项目存在问题,不会跨越屏幕宽度.对不起,如果我的代码很草率.这有点新鲜.我有类似代码的类似页面.

提前致谢!

不是完整的代码 - 不确定你是否需要它.

<ListView x:Name="listView" DataContext="{Binding ServicesCvs}" ItemsSource="{Binding}" Margin="0,80,0,0" HorizontalContentAlignment="Stretch">

                   <ListView.ItemTemplate>

                    <DataTemplate>
                        <Grid>

                                <Button Command="{Binding DataContext.SelectServiceCommand, ElementName=serviceSelectionPage}"
                                    CommandParameter="{Binding Text, ElementName=ServiceIdTextBlock}">
                                    <StackPanel Orientation="Horizontal" Margin="0,0,0,0">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto"/>
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="0*"/>
                                            <ColumnDefinition Width="1*"/>
                                            <ColumnDefinition Width="1*"/>
                                            <ColumnDefinition Width="1*"/>
                                            <ColumnDefinition Width="1*"/>
                                            <ColumnDefinition Width="Auto"/>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock x:Name="ServiceIdTextBlock" Grid.Column="1" FontFamily="Arial" Text="{Binding ServiceId}" Style="{StaticResource TitleTextBlockStyle}" TextWrapping="NoWrap" Foreground="#FF18417C" Margin="10,0,0,0"/>
                                        <TextBlock x:Name="ServiceType" Grid.Column="2" FontFamily="Arial" Text="{Binding ServiceTypeId}" Style="{StaticResource TitleTextBlockStyle}" TextWrapping="NoWrap" Foreground="#FF414B59"/>
                                        <TextBlock x:Name="AssetId_TextBlock" Grid.Column="3" FontFamily="Arial" Text="{Binding AssetId}" Style="{StaticResource TitleTextBlockStyle}" TextWrapping="NoWrap" Foreground="#FF4D7CC1"/>
                                        <TextBlock x:Name="ProductItemId_TextBlock" Grid.Column="4" FontFamily="Arial" Text="{Binding ProductItemId}" Style="{StaticResource TitleTextBlockStyle}" TextWrapping="NoWrap" Foreground="#FF414B59"/>

                                    </Grid>
                                </StackPanel>
                                </Button>
                            </Grid>

                    </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
Run Code Online (Sandbox Code Playgroud)

Ive*_*Ive 21

把它放在ListView中,它也可以在Designer中使用

<ListView.ItemContainerStyle>
    <Style TargetType="ListViewItem">
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    </Style>
</ListView.ItemContainerStyle>
Run Code Online (Sandbox Code Playgroud)

正如Mark Feldman所说,删除StackPanel并设置按钮的Horizo​​ntalContentAlignment ="Stretch".