MvvmCross / MvvmCross-Forms

Support for Xamarin.Forms on MvvmCross: The .NET MVVM framework for cross-platform solutions, including Xamarin.iOS, Xamarin.Android, Windows and Mac.
http://mvvmcross.com
6 stars 2 forks source link

Commands in the Xamarin forms demos will not fire when added to the details page #58

Closed ghost closed 7 years ago

ghost commented 8 years ago

To help us fix your issue, please provide the information in the below template.

Note: There is often little we can do without a minimal reproducible sample of the issue, so please provide that in a standalone git repository and link it here.

Please only file bugs verified on latest version of MvvmCross and stable Xamarin tools

Steps to reproduce

  1. Open the Xamarin forms example xaml or c# version
  2. Add a command to the todoviewmodel
  3. Add button on the todopage, make sure you setup the command binding.
  4. Run sample , click the new button

    Expected behavior

Commands should fire like they do with the rest of mvvmcross

Actual behavior

and does not fire

Configuration

Version: 4.x

Platform: iOS/Android/Windows UWP

All platforms . iOS, android and uwp

Cheesebaron commented 8 years ago

Please provide a description of how exactly you add the command binding

ghost commented 8 years ago

C#

goButton.SetBinding(Button.CommandProperty, new Binding("NavigateToReminder"));

XAML:

<Button Text="Open Reminder page" Command="{Binding NavigateToReminder}"/>

ViewModel command:

 public ICommand NavigateToReminder
        {
            get
            {
                               //code does not get this far as command not firing
                return new MvxCommand(async () =>
                {
                    //code does not get this far as command not firing
                });
            }
        }
Cheesebaron commented 8 years ago

I've formatted your post. Also there is a MvxAsyncCommand for async operations which you might want to use instead.

Will take a look if I can reproduce your issue.

ghost commented 8 years ago

MasterDetailPage-MvvmCross-master 4.zip

Attached example with code aboved added to the todolistpage & todolistviewmodel.

really appreciate if you can help resolve as this is a blocker for us moving forward.

Cheesebaron commented 8 years ago

Your sample uses unsupported and outdated nuget packages. Please update them to non-HotTuna.

Anyways. When navigating to the TodoListPage, and checking the BindingContext in OnAppearing, its BindingContext is MainViewModel and not TodoListViewModel. This is your problem.

Why this is the case, I have no idea. At least you now know what is going on...

ghost commented 8 years ago

Sample is directly from the Xamarin mvvmcross forms git repository.

Hence I think the issue is in the mvvmcross forms demo the team provided with mvvmcross forms.

ghost commented 8 years ago

Do you know who the mvvmcross forms owners is, maybe they can ahead some light on the issue.

Looks like all the detail view models are bound to the mainviewmodel.

Alternatively, how to force binding it to correct one after the fact. From what I recall there is a way to bind a page to multiple viewmodels

Cheesebaron commented 8 years ago

What is the link for that sample? I dunno who submitted it, a git blame could maybe reveal something.

ghost commented 8 years ago

Do you by any chance have another example where masterdetail is used with Xamarin forms version of mvvmcross . I like the examples on this Git location but no master detail example .

That will solve it for us

ghost commented 8 years ago

found the xamarin forms example source: https://github.com/xamarin/xamarin-forms-samples/tree/master/Navigation/MasterDetailPage

ghost commented 8 years ago

Apologies : here is the MVVM Cross forms one :https://github.com/robinmj/MasterDetailPage-MvvmCross

Cheesebaron commented 8 years ago

Which is not an official source. You could try ask the author of the sample. I don't think we have a sample showing MasterDetailPage. A PR showing this would be appreciated.

farlop commented 8 years ago

Hi! I'm working on a way to use a MasterDetailPage with MvxForms using a custom Presenter. I think that I could provide a PR with implementation and an example. Do you agree with this?

Cheesebaron commented 8 years ago

PRs are welcome.

farlop commented 8 years ago

OK, The PR is live now #60 Please check it to see if everything is fine.

ghost commented 8 years ago

When can PR #60 be merged and pushed to nuget store.