[UWP] Improve toolbar consistency on MasterDetailPage (#744)

* Improve toolbar consistency on MasterDetailPage

* Properly indent xaml page
This commit is contained in:
Jimmy Garrido 2017-03-06 14:19:36 -08:00 коммит произвёл Samantha Houts
Родитель 8bc7ba3faa
Коммит 65d8480519
7 изменённых файлов: 121 добавлений и 36 удалений

Просмотреть файл

@ -0,0 +1,44 @@
using System;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Bugzilla, 51553, "[UWP] Toolbar not shown on first Detail page", PlatformAffected.WinRT)]
public class Bugzilla51553 : TestMasterDetailPage
{
protected override void Init()
{
Master = new ContentPage
{
Title = "Master",
BackgroundColor = Color.Red
};
Detail = new NavigationPage(new TestPage());
}
class TestPage : ContentPage
{
public TestPage()
{
Title = "Test Page";
ToolbarItems.Add(new ToolbarItem("Test", "coffee.png", () => System.Diagnostics.Debug.WriteLine("ToolbarItem pressed")));
Content = new StackLayout
{
Children = {
new Label { Text = "If the ToolbarItem is not visible then this test has failed." }
}
};
}
}
}
}

Просмотреть файл

@ -0,0 +1,36 @@
using System;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Bugzilla, 51802, "[UWP] Detail Page Has Navigation Bar Even When Not Inside a NavigationPage", PlatformAffected.WinRT)]
public class Bugzilla51802 : TestMasterDetailPage
{
protected override void Init()
{
Master = new ContentPage
{
Title = "Master",
BackgroundColor = Color.Red
};
Detail = new ContentPage
{
Content = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
Children = {
new Label { Text = "If a navigation bar is present on this page then this test has failed." }
}
}
};
}
}
}

Просмотреть файл

@ -172,6 +172,8 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla47923.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla48236.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla47971.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla51553.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla51802.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla51236.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla51238.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla51642.xaml.cs">

Просмотреть файл

@ -294,6 +294,9 @@ namespace Xamarin.Forms.Platform.UWP
ContentTogglePaneButtonVisibility = _split.DisplayMode == SplitViewDisplayMode.Overlay
? Visibility.Visible
: Visibility.Collapsed;
if (ContentTogglePaneButtonVisibility == Visibility.Visible)
DetailTitleVisibility = Visibility.Visible;
}
}
}

Просмотреть файл

@ -29,26 +29,26 @@
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border x:Name="TopCommandBarArea" HorizontalAlignment="Stretch" Background="{TemplateBinding ToolbarBackground}">
<uwp:FormsCommandBar x:Name="CommandBar" Background="{TemplateBinding ToolbarBackground}" MinHeight="{ThemeResource TitleBarHeight}">
<uwp:FormsCommandBar.Content>
<Border x:Name="TitleArea" Height="{ThemeResource TitleBarHeight}">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Background="{TemplateBinding ToolbarBackground}" >
<Border x:Name="TopCommandBarArea" HorizontalAlignment="Stretch" Background="{TemplateBinding ToolbarBackground}">
<uwp:FormsCommandBar x:Name="CommandBar" Background="{TemplateBinding ToolbarBackground}" MinHeight="{ThemeResource TitleBarHeight}">
<uwp:FormsCommandBar.Content>
<Border x:Name="TitleArea" Height="{ThemeResource TitleBarHeight}" Visibility="{TemplateBinding DetailTitleVisibility}">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Background="{TemplateBinding ToolbarBackground}" >
<Button Name="ContentTogglePane" Style="{ThemeResource PaneButton}" Foreground="{TemplateBinding ToolbarForeground}"
Visibility="{TemplateBinding ContentTogglePaneButtonVisibility}" />
<Button Name="ContentTogglePane" Style="{ThemeResource PaneButton}" Foreground="{TemplateBinding ToolbarForeground}"
Visibility="{TemplateBinding ContentTogglePaneButtonVisibility}" />
<Border Height="{ThemeResource TitleBarHeight}" Visibility="{TemplateBinding DetailTitleVisibility}">
<TextBlock Text="{TemplateBinding DetailTitle}" VerticalAlignment="Center" Margin="10,0,0,0" Foreground="{TemplateBinding ToolbarForeground}" Style="{ThemeResource TitleTextBlockStyle}" />
</Border>
<Border Height="{ThemeResource TitleBarHeight}" Visibility="{TemplateBinding DetailTitleVisibility}">
<TextBlock Text="{TemplateBinding DetailTitle}" VerticalAlignment="Center" Margin="10,0,0,0" Foreground="{TemplateBinding ToolbarForeground}" Style="{ThemeResource TitleTextBlockStyle}" />
</Border>
</StackPanel>
</Border>
</uwp:FormsCommandBar.Content>
</uwp:FormsCommandBar>
</Border>
</StackPanel>
</Border>
</uwp:FormsCommandBar.Content>
</uwp:FormsCommandBar>
</Border>
<ContentPresenter x:Name="DetailPresenter" Grid.Row="1" Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Detail}" />
<ContentPresenter x:Name="DetailPresenter" Grid.Row="1" Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Detail}" />
<Border x:Name="BottomCommandBarArea" Grid.Row="2" HorizontalAlignment="Stretch"></Border>
</Grid>
@ -58,4 +58,4 @@
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
</ResourceDictionary>

Просмотреть файл

@ -146,19 +146,17 @@ namespace Xamarin.Forms.Platform.UWP
}
e.NewElement.PropertyChanged += OnElementPropertyChanged;
UpdateMode();
UpdateDetail();
UpdateMaster();
UpdateMode();
UpdateIsPresented();
if (!string.IsNullOrEmpty(e.NewElement.AutomationId))
Control.SetValue(AutomationProperties.AutomationIdProperty, e.NewElement.AutomationId);
#if WINDOWS_UWP
UpdateToolbarPlacement();
#endif
}
((ITitleProvider)this).BarBackgroundBrush = (Brush)Windows.UI.Xaml.Application.Current.Resources["SystemControlBackgroundChromeMediumLowBrush"];
UpdateToolbarPlacement();
}
}
protected virtual void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
@ -267,8 +265,7 @@ namespace Xamarin.Forms.Platform.UWP
IVisualElementRenderer renderer = _detail.GetOrCreateRenderer();
element = renderer.ContainerElement;
// Enforce consistency rules on toolbar (show toolbar if Detail is Navigation Page)
Control.ShouldShowToolbar = _detail is NavigationPage;
UpdateToolbarVisibilty();
}
Control.Detail = element;
@ -311,24 +308,28 @@ namespace Xamarin.Forms.Platform.UWP
Control.Master = element;
Control.MasterTitle = _master?.Title;
// Enforce consistency rules on toolbar (show toolbar if Master is Navigation Page)
Control.ShouldShowToolbar = _master is NavigationPage;
UpdateToolbarVisibilty();
}
void UpdateMode()
{
UpdateDetailTitle();
Control.CollapseStyle = Element.OnThisPlatform().GetCollapseStyle();
Control.CollapsedPaneWidth = Element.OnThisPlatform().CollapsedPaneWidth();
Control.ShouldShowSplitMode = MasterDetailPageController.ShouldShowSplitMode;
}
#if WINDOWS_UWP
void UpdateToolbarPlacement()
void UpdateToolbarPlacement()
{
Control.ToolbarPlacement = Element.OnThisPlatform().GetToolbarPlacement();
}
void UpdateToolbarVisibilty()
{
// Enforce consistency rules on toolbar
Control.ShouldShowToolbar = _detail is NavigationPage || _master is NavigationPage;
}
public void BindForegroundColor(AppBar appBar)
{
SetAppBarForegroundBinding(appBar);
@ -344,6 +345,5 @@ namespace Xamarin.Forms.Platform.UWP
element.SetBinding(Windows.UI.Xaml.Controls.Control.ForegroundProperty,
new Windows.UI.Xaml.Data.Binding { Path = new PropertyPath("Control.ToolbarForeground"), Source = this, RelativeSource = new RelativeSource { Mode = RelativeSourceMode.TemplatedParent } });
}
#endif
}
}

Просмотреть файл

@ -170,11 +170,6 @@ namespace Xamarin.Forms.Platform.WinRT
Tracker = new BackgroundTracker<PageControl>(Control.BackgroundProperty) { Element = (Page)element, Container = _container };
#if WINDOWS_UWP
// Enforce consistency rules on toolbar (show toolbar if top-level page is Navigation Page)
_container.ShouldShowToolbar = _parentMasterDetailPage == null && _parentMasterDetailPage == null;
#endif
SetPage(Element.CurrentPage, false, false);
_container.Loaded += OnLoaded;
@ -189,6 +184,11 @@ namespace Xamarin.Forms.Platform.WinRT
UpdateNavigationBarBackground();
UpdateToolbarPlacement();
#if WINDOWS_UWP
// Enforce consistency rules on toolbar (show toolbar if top-level page is Navigation Page)
_container.ShouldShowToolbar = _parentMasterDetailPage == null && _parentTabbedPage == null;
#endif
Element.PropertyChanged += OnElementPropertyChanged;
((INavigationPageController)Element).PushRequested += OnPushRequested;
((INavigationPageController)Element).PopRequested += OnPopRequested;