gpt4 book ai didi

mvvm - CollectionView RemainingItemsThreshholdReached 命令出错

转载 作者:行者123 更新时间:2023-12-03 10:31:38 25 4
gpt4 key购买 nike

我在我的应用程序中使用 Prism MVVM。所以这是我的 XAML 代码

 IsRefreshing="{Binding IsRefreshing}"
Command="{Binding RefreshCommand}">

<CollectionView ItemsSource="{Binding Images}"
RemainingItemsThreshold="1"
RemainingItemsThresholdReachedCommand="{Binding UpdateImagesCommand}">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical"
Span="3"/>
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid Padding="2">
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<ff:CachedImage
Grid.Row="0"
Grid.Column="0"
HorizontalOptions="Center"
VerticalOptions="Center"
Aspect="AspectFill"
Source="{Binding Source, Mode=OneWay}">
<ff:CachedImage.Transformations>
<ffTransformations:CropTransformation />
</ff:CachedImage.Transformations>
</ff:CachedImage>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</RefreshView>

正如您在此处看到的,我的参数 RemainingItemsThreshold 的值为“1”,并将 anUpdateImagesCommand 绑定(bind)到 RemainingItemsThresholdReachedCommand

这是此 xaml 页面的 View 模型中的代码的一部分
private ObservableCollection _images;
public ObservableCollection Images
{
get { return _images; }
set { SetProperty(ref _images, value); }
}
private DelegateCommand _refreshCommand;
public DelegateCommand RefreshCommand =>
_refreshCommand ?? (_refreshCommand = new DelegateCommand(ExecuteRefreshCommand));
private DelegateCommand _updateImagesCommand;
public DelegateCommand UpdateImagesCommand =>
_updateImagesCommand ?? (_updateImagesCommand = new DelegateCommand(ExecuteUpdateImagesCommand));
void ExecuteUpdateImagesCommand()
{
//Image im = new Image();
//im.Source = "Huayra3.jpg";
//Image im7 = new Image();
//im7.Source = "Huayra1.jpg";
//Images.Add(im7);
//Images.Add(im7);
//Images.Add(im);
//Images.Add(im);
//Images.Add(im);
//Images.Add(im);
}
void ExecuteRefreshCommand()
{
// refresh posts feed command
IsRefreshing = false;
}

public AccountPageViewModel(INavigationService navigationService, IUserDataService userDataService) :
base(navigationService)
{
_userDataService = userDataService;
CurrentUser = userDataService.CurrentUser;
if (String.IsNullOrEmpty(this.CurrentUser.ImagePath))
{
this.CurrentUser.ImagePath = "user_avatar.jpg";
}

Images = new ObservableCollection<Image>();

Image im = new Image();
im.Source = "Huayra3.jpg";
Images.Add(im);
Image im1 = new Image();
im1.Source = "Huayra1.jpg";
Images.Add(im1);
Image im2 = new Image();
im2.Source = "Huayra4.jpg";
Images.Add(im2);
Image im3 = new Image();
im3.Source = "Huayra3.jpg";
Images.Add(im3);
Image im4 = new Image();
im4.Source = "Huayra1.jpg";
Images.Add(im4);
Image im5 = new Image();
im5.Source = "Huayra4.jpg";
Images.Add(im5);
Image im6 = new Image();
im6.Source = "Huayra3.jpg";
Images.Add(im6);
Image im7 = new Image();
im7.Source = "Huayra1.jpg";
Images.Add(im7);
Images.Add(im7);

Images.Add(im7);
Images.Add(im7);
Images.Add(im7);
Images.Add(im7);
Images.Add(im7);
Images.Add(im);


//Images.Add(im);
//Images.Add(im);

}

如您所见,我在 VIewModel 构造函数中编写了一些值并将其添加到列表中。我阅读了有关 CollectionView 的 Microsoft 文档,并且我知道 UpdateImagesCommand 仅在达到 RemainingItemsThreshold 时才会执行。但是当我导航到此页面时,当我在标签页中的页面之间随机导航时,ExecuteUpdateImagesCommand() 会调用。这不应该,但我不知道发生这种情况的原因。 smbd可以帮我吗?

最佳答案

我找到了另一种方法来解决这个问题。我可以使用 IsActive PRISM 属性来了解该页面是我需要的。

关于mvvm - CollectionView RemainingItemsThreshholdReached 命令出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60024485/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com