Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inner Items in UWP Grid not stretching XAML

Tags:

wpf

xaml

uwp

Having an issue with my items in this list view not spanning the width of the screen. Sorry if my code is sloppy. A bit new at this. I do have similar pages with similar code.

Thanks in advance!

Not the full code - wasn't sure if you would need it.

<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>
like image 890
Tilcey Avatar asked Nov 27 '22 16:11

Tilcey


1 Answers

Put this in your ListView, it will works in Designer too

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

And as Mark Feldman said, remove that StackPanel and set button's HorizontalContentAlignment="Stretch".

like image 119
Ive Avatar answered Dec 06 '22 20:12

Ive