2

i have this xaml code:

<ListView Name="MyList" ItemsSource="{Binding MyItems}"
        ScrollViewer.HorizontalScrollMode="Disabled" >
        <ListView.ItemTemplate>
            <DataTemplate>
                <Grid Width="{Binding ElementName=MyList, Path=ActualWidth}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="100"/>
                        <ColumnDefinition Width="50"/>
                    </Grid.ColumnDefinitions>
                    <StackPanel Orientation="Vertical" Grid.Column="0" Grid.ColumnSpan="2" >
                        <TextBlock Text="{Binding aaa}" />
                        <TextBlock Text="{Binding bbb}" />
                        <TextBlock Text="{Binding ccc}" 
                            TextWrapping="WrapWholeWords" TextTrimming="WordEllipsis" Height="25" MaxHeight="25"  Margin="0,0,10,0" />
                    </StackPanel>
                    <TextBlock Grid.Column="1" Style="{StaticResource ListTitle}" Text="{Binding restaDaPagare}"
                                   HorizontalAlignment="Right" Margin="0,0,10,0" />
                    <Canvas Grid.Column="2" Height="50" Width="50" Background="{StaticResource GrayBrush}"></Canvas>
                    <Image Grid.Column="2" Source="/Images/img.png" 
                                   Height="50" Width="50" MinHeight="50" MinWidth="50"/>
                </Grid>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

For some reasons, if i use this instruction (row 5):

<Grid Width="{Binding ElementName=MyList, Path=ActualWidth}">

the first item of MyList disappears. If i use this code:

<Grid Width="400">

everything works well... except that I don't want to use a static Width. Thanks for any help!

BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117
ful03
  • 23
  • 3

1 Answers1

3

You can try to not set any width for your Grid (in your template) and add this to your ListView

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

This idea was "taken" from this question

Community
  • 1
  • 1
meneses.pt
  • 2,588
  • 3
  • 27
  • 38
  • Thanks a lot... this worked! I've probably missed the response where you took the idea because it haven't windows phone tag. – ful03 Nov 25 '14 at 10:52