How bad is this code?

clopezclopez ESMember ✭✭✭

Hello again:

This is not realted with previous questions at all, and want to know how bad is what I'm going to propose.
I wanted to pass a value to the previous page, but I though that to pass the entire ViewModel from one page to another just for this was too much.
The idea is to pass to the parent page filter the ID of a item created on the child page. That way, the parent list will shows only the recently created item, so, from the child ViewModel I added this to the CreateItem command:

                    if ((Navigation != null) && (Navigation.NavigationStack.Count >= 2))
                        Page tempPage = Navigation.NavigationStack[Navigation.NavigationStack.Count - 2];
                        ((ParentViewModel)tempPage.BindingContext).SearchBarTextToFind = newItem.ToString();
                    await Navigation.PopAsync();

I think this is bad coding, but I'm just getting a page, and only modifying his ViewModel (a binded variable to the form), and it works, but should I change it?


Best Answers


  • clopezclopez ESMember ✭✭✭

    Sounds good and easy enough. For some reason, the messaging center I had found was WAY more complex than what I found using yours words :sweat:
    And the example that I'm checking for learning doesn't use it at all, so I though there was a reason for it :disappointed:

    If I understood correctly, both, subscription and send must be done in ViewModels, right?

Sign In or Register to comment.