简体   繁体   English

如何修复listview Windows Phone 8.1 XAML内部的错误

[英]How to fix a bug inside of listview Windows Phone 8.1 XAML

I made a list within a HUB and managed successfully, but when I try to create a style to separate the items to be listed I have a very strange bug when I try to slide down in the middle of the list he began to shake just becauseI added a margin, if I remove works normally. 我在HUB内创建了一个列表并成功进行了管理,但是当我尝试创建一种样式来分隔要列出的项目时,当我尝试滑入列表中间时,他遇到了一个非常奇怪的错误,他只是因为我而开始动摇如果我正常删除,则增加了边距。

heres my code! 这是我的代码!

<ListView x:Name="list" Loaded="ListView_Loaded" SelectedItem="true"  SelectionChanged="searchResultsList_SelectionChanged" ItemsSource="{Binding}">
                                    <ListView.ItemContainerStyle>
                                        <Style TargetType="ListViewItem">
                                            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                                            <Setter Property="Margin" Value="0,0,0,20" />
                                        </Style>
                                    </ListView.ItemContainerStyle>
                                    <ListView.ItemTemplate>
                                        <DataTemplate>
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="80" />
                                                    <ColumnDefinition Width="10" />
                                                    <ColumnDefinition Width="*" />
                                                </Grid.ColumnDefinitions>

                                                <Border Width="80" Height="80">
                                                    <Image Source="{Binding Caminho}" />
                                                </Border>

                                                <StackPanel Margin="0,16,0,0" Grid.Column="2">
                                                    <TextBlock Foreground="White" Text="{Binding NomeCurso}" TextWrapping="WrapWholeWords" FontSize="{StaticResource TextStyleExtraLargeFontSize}" />

                                                </StackPanel>
                                            </Grid>
                                        </DataTemplate>
                                    </ListView.ItemTemplate>
                                </ListView>

so my bug is specially in this part of code : 所以我的错误特别是在这部分代码中:

<Setter Property="Margin" Value="0,0,0,20" />

if i leave this Works well,somebody knows what is it ? 如果我离开此工作正常,有人知道这是什么吗?

That is strange it should work. 奇怪的是它应该起作用。 but to fix your issue you can use margin with your datatemplate grid. 但是要解决您的问题,您可以在数据模板网格中使用边距。 set margin to the main grid of listitem data template 将边距设置为listitem数据模板的主网格

   <DataTemplate>
                                        <Grid Margin="0,0,0,20">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="80" />
                                                <ColumnDefinition Width="10" />
                                                <ColumnDefinition Width="*" />
                                            </Grid.ColumnDefinitions>

                                            <Border Width="80" Height="80">
                                                <Image Source="{Binding Caminho}" />
                                            </Border>

                                            <StackPanel Margin="0,16,0,0" Grid.Column="2">
                                                <TextBlock Foreground="White" Text="{Binding NomeCurso}" TextWrapping="WrapWholeWords" FontSize="{StaticResource TextStyleExtraLargeFontSize}" />

                                            </StackPanel>
                                        </Grid>
                                    </DataTemplate>

This is a bug in WP 8.1 and it has something to do with virutalization. 这是WP 8.1中的错误,与虚拟化有关。

You need to specify the width explicitly for each item or use what I use (thanks to Rudy ), which is an extended ListView that fixes this problem and the margins will still work: 您需要为每个项目明确指定宽度或使用我使用的宽度(感谢Rudy ),这是扩展的ListView ,它可以解决此问题,并且边距仍然可以使用:

public class PerfectScrollListView : ListView
{
    public PerfectScrollListView()
    {
        this.SizeChanged += PerfectScrollListView_SizeChanged;
    }

    private void PerfectScrollListView_SizeChanged(object sender, SizeChangedEventArgs e)
    {
        if (ItemsPanelRoot != null)
        {
            ItemsPanelRoot.Width = e.NewSize.Width;
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM