【发布时间】:2020-07-31 07:27:49
【问题描述】:
这是我的第一个 xamarin 格式的应用程序。我需要修改列表顺序,但找不到方法。我需要按AutoModelo 的顺序显示它。我将源代码发送给您,以防有人可以帮助我。
这是模型/Auto.cs
{
public class Auto
{
public Guid AutoID { get; set; }
public string AutoPatente { get; set; }
public string AutoModelo { get; set; }
public string AutoColor { get; set; }
public bool AutoLuces { get; set; }
public int AutoKmtablero { get; set; }
public List<Actividad> Actividades { get; set; }
}
}
这是 ViewModels/AutoListPageViewModel
namespace CracApp.ViewModels
{
public class AutoListPageViewModel : BaseViewModel
{
string controller = Constants.AutosApi;
public INavigation Navigation { get; set; }
public ICommand NewAutoCommand { get; set; }
public ICommand ViewAutoCommand { get; set; }
Auto selectedAuto;
public Auto SelectedAuto
{
get => selectedAuto;
set { selectedAuto = value; RaisePropertyChanged(); }
}
private ObservableCollection<Auto> autosList;
//Collection = new ObservableCollection(Collection.OrderBy(x=>x.Date).ToList());
public ObservableCollection<Auto> AutosList
{
get => autosList;
set {
autosList = value;
RaisePropertyChanged();
}
}
public AutoListPageViewModel(INavigation navigation)
{
Navigation = navigation;
NewAutoCommand = new Command(async () => await NewAuto());
ViewAutoCommand = new Command(async () => await ViewAuto());
}
public async Task LoadData()
{
IsBusy = true;
AutosList = new ObservableCollection<Auto>(await AutoService<Auto>.GetData(controller));
//Collection = new ObservableCollection(Collection.OrderBy(x=>x.Date).ToList());
IsBusy = false;
}
async Task NewAuto()
{
//await Navigation.PushAsync(new Views.AutoDetailPage (new AutoDetailViewModel (new Auto(), Navigation)));
//await Navigation.PushAsync(new Views.ActividadListPage(new ActividadListPageViewModel(new Actividad(), Navigation)));
//await Navigation.PushAsync(new ActividadListPage(new ActividadListPageViewModel(new Actividad(), Navigation)));
await Navigation.PushAsync(new ActividadListPage());
}
async Task ViewAuto()
{
if (SelectedAuto != null)
{
await Navigation.PushAsync(new Views.AutoDetailPage(new AutoDetailViewModel(SelectedAuto, Navigation)));
}
}
}
}
【问题讨论】:
-
您能否标记/接受对您有帮助的答案,以便我们可以帮助更多有同样问题的人:)。
-
是的,当然。我应该在页面的哪个位置进行操作?
-
您的页面中应该有一个“接受”选项。
-
你能标记答案吗?
标签: xamarin.forms