HomePage.xaml
Код: Выделить всё
Код: Выделить всё
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using EventWebApp.Models;
using EventWebApp.Services;
using Xamarin.Forms;
namespace EventWebApp.ViewModels
{
public class HomeViewModel : EventsInterface
{
public int UserId { get; private set; }
public HomeViewModel()
{
Title = "Home";
JoinEvent = new Command(OnJoin);
_ = LoadEventsAsync();
}
public void SetUserId(int userId)
{
UserId = userId;
LoadEventsForUser(userId);
}
private async void LoadEventsForUser(int userId)
{
var user = await new UserInterface().GetUser(userId);
if (user != null)
{
Title = $"Welcome, {user.FirstName} {user.LastName}!";
}
}
public Command JoinEvent { get; }
// This is be the line of code I want to execute if I clicked the Join button
private async void OnJoin(Event selectedEvent)
{
if (selectedEvent == null)
return;
// Display event details in an alert
await Shell.Current.DisplayAlert(
"Event Joined",
$"You have joined the event:\n\n" +
$"ID: {selectedEvent.event_id}\n" +
$"Name: {selectedEvent.event_name}",
"OK");
}
}
}
Я ожидаю, что сейчас отобразится предупреждение, показывающее, что моя кнопка работает правильно, но, к сожалению, всякий раз, когда я добавляю команду привязки к своей кнопке, содержимое не отображается.
Подробнее здесь: https://stackoverflow.com/questions/792 ... arin-forms
Мобильная версия