Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Partial Views in Xamarin Forms #1519

Merged
merged 10 commits into from
Sep 20, 2018
Merged

Support Partial Views in Xamarin Forms #1519

merged 10 commits into from
Sep 20, 2018

Conversation

dansiegel
Copy link
Member

Description of Change

Adds an ability to support Partial Views that have their own ViewModel which can be reused across multiple Pages in a single application. This sets the AutowireViewModel property behind the scenes and updates the ResolveViewModelForView in each of the Container projects to look for an associated Page if the View is not a Page.

Example

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
                xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
                xmlns:local="using:AwesomeProject.Views"
                x:Name="page"
                x:Class="AwesomeProject.Views.ViewA">
  <local:MyCustomView prism:ViewModelLocator.AutowirePartialView="{x:Reference page}" />
</ContentPage>
public class MyCustomViewModel : BindableBase
{
    public MyCustomViewModel(INavigationService navigationService)
    {
        // The navigationService can now be used....
    }
}

API Changes

Added:

  • BindableProperty ViewModelLocator.AutowirePartialView. This takes a reference to the associated Page
    • This allows us to make minimal changes and not need to wait and recurse the Element.Parent, as ViewModelLocator.AutowireViewModel is set prior to the Parent being set on the Element.

Behavioral Changes

  • void PageUtilities.InvokeViewAndViewModelAction => Added check to see if view is Xamarin.Forms.Page and if it has any PartialViews. If it does the InvokeAction is called for each Partial View.

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Rebased on top of master at time of PR
  • Changes adhere to coding standard

@mackayn
Copy link

mackayn commented Aug 1, 2018

This PR is exactly what we're looking for.

@YZahringer
Copy link

Can be released with 7.1 or next preview?

@dansiegel
Copy link
Member Author

this is still TBD.... @brianlagunas and I are still determining how the feature should work and whether we should go with something simple like this, or more complex where we introduce Regions to Xamarin Forms like we have in WPF.

@YZahringer
Copy link

The Regions would be really useful but in the meantime, this solution allows to split views. Very useful while waiting for the Regions maybe in a future version.

@mackayn
Copy link

mackayn commented Aug 21, 2018

We really really really need this in 7.1, go with what's implemented for now.....pleeeease.

@brianlagunas brianlagunas merged commit f50103f into master Sep 20, 2018
@dansiegel dansiegel deleted the xf-partialviews branch September 20, 2018 20:25
@Snsaiu
Copy link

Snsaiu commented Jan 21, 2020

when l use partial view,binding property can not work.how to fix?

@dansiegel
Copy link
Member Author

@Snsaiu if you have a question please ask it on StackOverflow. If you believe you have run into a bug please open an issue and provide a sample reproducing the issue.

@lock
Copy link

lock bot commented Feb 4, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Feb 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants