-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1519 from PrismLibrary/xf-partialviews
Support Partial Views in Xamarin Forms
- Loading branch information
Showing
28 changed files
with
529 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
Sandbox/Xamarin/HelloWorld/ModuleA/ViewModels/PartialViewBViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using Prism.Commands; | ||
using Prism.Mvvm; | ||
using Prism.Navigation; | ||
|
||
namespace ModuleA.ViewModels | ||
{ | ||
public class PartialViewBViewModel : BindableBase | ||
{ | ||
private INavigationService _navigationService { get; } | ||
|
||
public PartialViewBViewModel(INavigationService navigationService, IApplicationCommands applicationCommands) | ||
{ | ||
_navigationService = navigationService; | ||
NavigateCommand = new DelegateCommand(Navigate).ObservesCanExecute(() => CanNavigate); | ||
SaveCommand = new DelegateCommand(Save); | ||
ResetCommand = new DelegateCommand(Reset); | ||
|
||
applicationCommands.SaveCommand.RegisterCommand(SaveCommand); | ||
applicationCommands.ResetCommand.RegisterCommand(ResetCommand); | ||
} | ||
|
||
private string _title = "View B"; | ||
public string Title | ||
{ | ||
get { return _title; } | ||
set { SetProperty(ref _title, value); } | ||
} | ||
|
||
private bool _canNavigate = true; | ||
public bool CanNavigate | ||
{ | ||
get { return _canNavigate; } | ||
set { SetProperty(ref _canNavigate, value); } | ||
} | ||
|
||
public event EventHandler IsActiveChanged; | ||
|
||
private bool _isActive; | ||
public bool IsActive | ||
{ | ||
get { return _isActive; } | ||
set | ||
{ | ||
SetProperty(ref _isActive, value); | ||
OnActiveChanged(); | ||
} | ||
} | ||
|
||
public DelegateCommand NavigateCommand { get; } | ||
|
||
public DelegateCommand SaveCommand { get; } | ||
|
||
public DelegateCommand ResetCommand { get; } | ||
|
||
private void Reset() | ||
{ | ||
Title = "View B"; | ||
} | ||
|
||
async void Navigate() | ||
{ | ||
CanNavigate = false; | ||
await _navigationService.NavigateAsync("ViewA"); | ||
CanNavigate = true; | ||
} | ||
|
||
private void Save() | ||
{ | ||
Title = "Saved"; | ||
} | ||
|
||
void OnActiveChanged() | ||
{ | ||
IsActiveChanged?.Invoke(this, EventArgs.Empty); | ||
SaveCommand.IsActive = IsActive; | ||
} | ||
|
||
public void OnNavigatedFrom(INavigationParameters parameters) | ||
{ | ||
|
||
} | ||
|
||
public void OnNavigatedTo(INavigationParameters parameters) | ||
{ | ||
Debug.WriteLine("Navigated to ViewB"); | ||
} | ||
|
||
public void OnNavigatingTo(INavigationParameters parameters) | ||
{ | ||
|
||
} | ||
|
||
public void OnAppearing() | ||
{ | ||
Debug.WriteLine("ViewB is appearing"); | ||
} | ||
|
||
public void OnDisappearing() | ||
{ | ||
Debug.WriteLine("ViewB is disappearing"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<StackLayout xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="ModuleA.Views.PartialViewB"> | ||
<Label Text="{Binding Title}" VerticalOptions="Center" HorizontalOptions="Center" /> | ||
<Label Text="{Binding IsActive}" /> | ||
<Button Command="{Binding NavigateCommand}" Text="Navigate" /> | ||
</StackLayout> |
13 changes: 13 additions & 0 deletions
13
Sandbox/Xamarin/HelloWorld/ModuleA/Views/PartialViewB.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Xamarin.Forms.Xaml; | ||
|
||
namespace ModuleA.Views | ||
{ | ||
[XamlCompilation(XamlCompilationOptions.Compile)] | ||
public partial class PartialViewB | ||
{ | ||
public PartialViewB () | ||
{ | ||
InitializeComponent (); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:local="clr-namespace:ModuleA.Views" | ||
xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms" | ||
prism:ViewModelLocator.AutowireViewModel="True" | ||
x:Class="ModuleA.Views.ViewB" | ||
x:Name="viewB" | ||
Title="View B"> | ||
<ContentPage.Padding> | ||
<OnPlatform x:TypeArguments="Thickness"> | ||
<On Platform="iOS" Value="0,20,0,0" /> | ||
</OnPlatform> | ||
</ContentPage.Padding> | ||
|
||
<StackLayout> | ||
<Label Text="{Binding Title}" VerticalOptions="Center" HorizontalOptions="Center" /> | ||
<Label Text="{Binding IsActive}" /> | ||
<Button Command="{Binding NavigateCommand}" Text="Navigate" /> | ||
</StackLayout> | ||
<local:PartialViewB prism:ViewModelLocator.AutowirePartialView="{x:Reference viewB}" /> | ||
<!--<StackLayout> | ||
<Label Text="{Binding Title}" VerticalOptions="Center" HorizontalOptions="Center" /> | ||
<Label Text="{Binding IsActive}" /> | ||
<Button Command="{Binding NavigateCommand}" Text="Navigate" /> | ||
</StackLayout>--> | ||
|
||
</ContentPage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
Source/Xamarin/Prism.DI.Forms.Tests/Fixtures/FixtureBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Prism.DI.Forms.Tests.Mocks; | ||
using Xamarin.Forms; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Prism.DI.Forms.Tests.Fixtures | ||
{ | ||
public abstract class FixtureBase | ||
{ | ||
protected ITestOutputHelper _testOutputHelper { get; } | ||
|
||
public FixtureBase(ITestOutputHelper testOutputHelper) | ||
{ | ||
_testOutputHelper = testOutputHelper; | ||
Xamarin.Forms.Mocks.MockForms.Init(); | ||
} | ||
|
||
protected PrismApplicationMock CreateMockApplication(Page view = null) | ||
{ | ||
var initializer = new XunitPlatformInitializer(_testOutputHelper); | ||
return view == null ? new PrismApplicationMock(initializer) : new PrismApplicationMock(initializer, view); | ||
} | ||
} | ||
} |
Oops, something went wrong.