У меня есть приложение Xamarin.Forms UWP с ListView в нем. ListView содержит среди прочего большие изображения. Вскоре после загрузки, когда я начинаю прокручивать ListView, возникает исключение OutOfMemory. Я пытался использовать разбиение по страницам, чтобы уменьшить ListView, но после нескольких нажатий Next, исключение все равно происходит. Интересно, как я могу освободить память, например при нажатии на кнопку Далее.
Вот код:
<StackLayout>
<ListView x:Name="ProductView" Margin="20">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Source="{Binding Front_Image, StringFormat='https://cdn.mysite.com{0}'}" Grid.Column="0" />
<Label Text="{Binding Name}" Grid.Column="1" FontAttributes="Bold" VerticalOptions="Center" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Button x:Name="Prev" Text="Previous" Style="{StaticResource NavButton}" Clicked="OnPrevClicked" IsEnabled="false" />
<Button x:Name="Next" Text="Next" Style="{StaticResource NavButton}" Clicked="OnNextClicked" />
</StackLayout>
...
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ProductsPage : ContentPage
{
//public ObservableCollection<Product> Products { get; set; }
private int PageNumber { get; set; } = 1;
public ProductsPage ()
{
InitializeComponent();
ProductView.ItemsSource = Product.GetProducts(PageNumber);
}
private void OnPrevClicked(object sender, EventArgs args)
{
ProductView.ItemsSource = Product.GetProducts(--PageNumber);
Prev.IsEnabled = PageNumber > 1;
}
private void OnNextClicked(object sender, EventArgs args)
{
ProductView.ItemsSource = Product.GetProducts(++PageNumber);
Prev.IsEnabled = true;
}
}