Witam. Ostatnio zacząłem uczyć się Xamarin Form'sów i napotkałem na mały problem...
Mam taką oto klasę:
using GalaSoft.MvvmLight;
namespace TestMvvmApp.ViewModel.Menu
{
public class RootPageViewModel : ViewModelBase
{
public RootPageViewModel()
{
IsPresented = true;
}
private bool _IsPresented;
public bool IsPresented
{
get { return _IsPresented; }
set { Set(() => IsPresented, ref _IsPresented, value); }
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TestMvvmApp.View.Menu.RootPage"
IsPresented="{Binding IsPresented}">
</MasterDetailPage>
Oraz drugą klasę:
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System.Collections.ObjectModel;
using System.Windows.Input;
namespace TestMvvmApp.ViewModel.Menu
{
public class MenuPageViewModel : ViewModelBase
{
private RootPageViewModel rootPageViewModel;
private ObservableCollection<MenuItem> _Items = new ObservableCollection<MenuItem>();
public ObservableCollection<MenuItem> Items
{
get { return _Items; }
set { Set(() => Items, ref _Items, value); }
}
public ICommand ItemSelectedCommand { get; set; }
public MenuPageViewModel(RootPageViewModel rootPageViewModel)
{
this.rootPageViewModel = rootPageViewModel;
ItemSelectedCommand = new RelayCommand(ItemSelectedMethod);
Items.Add(new MenuItem("Home"));
Items.Add(new MenuItem("Page 1"));
}
private async void ItemSelectedMethod()
{
await App.Current.MainPage.DisplayAlert("menu", rootPageViewModel.IsPresented.ToString(), "OK");
rootPageViewModel.IsPresented = false;
}
}
public class MenuItem
{
public string Title { get; set; }
public MenuItem(string Title)
{
this.Title = Title;
}
}
}
Problem w tym, że kiedy ustawiam wartość rootPageViewModel.IsPresented = false;, View reaguje tylko za pierwszym wywołaniem komendy. Kiedy po drugim kliknięciu wyświetli się menu i kliknie się w nim jakiś "przycisk" to linijka await App.Current.MainPage.DisplayAlert("menu", rootPageViewModel.IsPresented.ToString(), "OK"); - zwraca false (chociaż powinna true, bo kliknięcie w przycisk rozsuwający menu powinien zmienić wartość właściwości na taką). Wiecie o co może chodzić? Będę wdzięczny za każdą pomoc.
Pozdrawiam :)