【发布时间】:2017-10-20 19:19:32
【问题描述】:
谁能告诉我我的代码有什么问题?我正在尝试让刷新以在我的 xaml 页面上工作,但它不适用于 Android 或 iPhone。我认为这可能是我的列表视图布局方式。谁能告诉我 ListView 中是否有可能阻止刷新命令触发的东西?这是我的 ListView 的 xaml 代码
<ContentPage.Content>
<ListView x:Name="TDRView" HasUnevenRows="True" ItemTapped="OnItemTapped" IsPullToRefreshEnabled="True" RefreshCommand="{Binding RefreshCommand}" IsRefreshing="{Binding IsRefreshing}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Grid x:Name ="gridTDR">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50*" />
<ColumnDefinition Width="25*" />
<ColumnDefinition Width="25*" />
</Grid.ColumnDefinitions>
<StackLayout HorizontalOptions="StartAndExpand" VerticalOptions="CenterAndExpand" Grid.Column="0" Grid.Row="0">
<Label x:Name="lblTDRID" Text="{Binding TDRID}" IsVisible="false" />
<Label x:Name="lblCustName" Text="{Binding CustomerName}" FontSize="Medium" TextColor="Black" />
</StackLayout>
<Button Image="iconApprove.png" Clicked="OnApproveButtonClicked" Grid.Column="1" Grid.Row="0" VerticalOptions="Center" BackgroundColor="Transparent" />
<Button Image="iconReject.png" Clicked="OnRejectButtonClicked" Grid.Column="2" Grid.Row="0" VerticalOptions="Center" BackgroundColor="Transparent" />
</Grid>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
下面是代码中的方法...
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Forms;
namespace AppNameSpace
{
public partial class MainPage : ContentPage
{
ObservableCollection<TDR> collection = new ObservableCollection<TDR>();
private bool _isRefreshing = false;
public bool IsRefreshing
{
get { return _isRefreshing; }
set
{
_isRefreshing = value;
OnPropertyChanged(nameof(IsRefreshing));
}
}
public ICommand RefreshCommand
{
get
{
return new Command(async () =>
{
IsRefreshing = true;
await Service.GetPendingTDRs();
IsRefreshing = false;
});
}
}
public MainPage()
{
InitializeComponent();
TDRView.ItemsSource = collection;
GetTDRs();
}
}
}
谢谢!
【问题讨论】:
-
您是否真的使用调试器来验证刷新 cmd 是否正在触发?
-
是的,我已经调试并设置了断点,它不会可怕
-
当您说“它不工作”时,您的意思是在 iOS 中,例如,当拉动列表时,指示器出现并开始旋转,但它继续像这样继续并且列表永远不会刷新?您还可以更新您的帖子,显示您的完整代码吗?
-
没错。我只得到纺车。如果后面的代码发生任何事情,它不会出现。
-
我已经把剩下的代码贴在后面了。谢谢
标签: .net xaml xamarin xamarin.forms cross-platform