コード例 #1
0
        private static void TestGroupViewModel(
            IGroupLoaderService loaderService,
            string expectedName,
            string expectedDescription,
            string expectedImageUrl)
        {
            var groupViewModel = new GroupPageViewModel(loaderService);

            WaitForPropertyChanged(
                groupViewModel,
                () => groupViewModel.RefreshDataCommand.Execute(null),
                pce => pce.PropertyName == nameof(groupViewModel.Name));

            groupViewModel.Name.Should().Be(expectedName);
            groupViewModel.Description.Should().Be(expectedDescription);
            groupViewModel.ImageUrl.Should().Be(expectedImageUrl);
        }
コード例 #2
0
        public GroupPage(GroupPageViewModel vm, bool createMenu = false)
        {
            InitializeComponent();
            BindingContext = viewModel = vm;
            MessagingCenter.Subscribe <GroupPageViewModel>(this, "ClearEntries", (s) =>
            {
                PostName.Text = "";
                Body.Text     = "";
            });

            MessagingCenter.Subscribe <GroupsPage>(this, "LoadPosts", (sender) => viewModel.LoadPosts.Execute(null));
            Body.TextChanged += (sender, args) =>
            {
                if (!string.IsNullOrEmpty(args.NewTextValue))
                {
                    if (args.NewTextValue[args.NewTextValue.Length - 1] == ' ' && args.NewTextValue.Contains('#'))
                    {
                        int hash_index = args.NewTextValue.IndexOf('#');
                        var tag        = args.NewTextValue.Substring(hash_index);
                        Device.BeginInvokeOnMainThread(() => viewModel.Tags.Add(tag.Trim()));
                        Body.Text = Body.Text.Remove(hash_index);
                    }
                }
            };

            if (createMenu)
            {
                this.ToolbarItems.Add(new ToolbarItem("Удалить", "", async() =>
                {
                    var shouldDelete = await DisplayAlert(null, "Удалить группу", "Да", "Нет");
                    if (shouldDelete)
                    {
                        viewModel.DeleteGroup.Execute(null);
                        MessagingCenter.Send <GroupPage, string>(this, "RemoveGroup", viewModel.Group.ID);
                        await Navigation.PopAsync();
                    }
                }, ToolbarItemOrder.Secondary));

                this.ToolbarItems.Add(new ToolbarItem("Редактировать", "", async() =>
                {
                    await Navigation.PushAsync(new CreateGroupPage(this.Navigation, viewModel.Group));
                }, ToolbarItemOrder.Secondary));
            }
        }
コード例 #3
0
        public GroupPage(Group g)
        {
            InitializeComponent();

            DataContext = new GroupPageViewModel(g);
        }
コード例 #4
0
 public GroupPage()
 {
     InitializeComponent();
     _viewModel     = DependencyInjection.Container.GetInstance <GroupPageViewModel>();
     BindingContext = _viewModel;
 }