diff options
author | Samantha Houts <samantha@teamredwall.com> | 2016-08-30 10:46:14 -0700 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-08-30 10:46:14 -0700 |
commit | 5e553f6195e66e48688b8ab324f1bab1e9251f0a (patch) | |
tree | f8843e5e9e8afe89a05a1cc91c3b7fa05588bac7 /Xamarin.Forms.Controls | |
parent | f551654b1cfe654c579ca50978445e7cb93f287d (diff) | |
download | xamarin-forms-5e553f6195e66e48688b8ab324f1bab1e9251f0a.tar.gz xamarin-forms-5e553f6195e66e48688b8ab324f1bab1e9251f0a.tar.bz2 xamarin-forms-5e553f6195e66e48688b8ab324f1bab1e9251f0a.zip |
Platform Specifics (#301)
* Playing around with how the platform specifics interfaces etc. might work
* Sample implementation of iOS navigation translucency
* Very slightly reduced code
* Better vendor stuff
* Drop single-implemenation interfaces
* Generics on NavigationPage
* On-demand vendor stuff
* Remove functionally duplicate classes and make ControlGallery work again
* Namespace all the things. XAML test.
* Can use Effect to attach platform specific
* Attach Effect on PropertyChanging for XAML support!
* Rename IConfigPlatform interfaces for readability
* Some renaming to match the documents
* Split class files
* Clear out test-only code
* Re-namespace
* Added On method to rendered Elements
* Allow for removal of platform suffix, convenience methods on specific platforms
* Creating a gallery page for specifics
* Add rudimentary Platform Specifics gallery; make CollapseStyle work on UWP;
Add CollapsedPaneWidth specific property
* Toolbar now working with both collapse styles
* MDP now displaying Content title; toolbar routing around title
* Add a gallery for the iOS NavigationPage stuff
* Add Navigation Page as detail page to verify it works with new Toolbar options
* Make titlebar/toolbar background colors consistent
* ToolbarPlacement now working on NavigationPage
* Toolbar Placement working for tabbed and nav pages
* Fix bug where phone doesn't get default toolbar placement on start
* [Core] Add PS WindowSoftInputModeAdjust
[Core] Make Application extendable
* Toolbar placement now working on Nav, Tabbed, and Master pages on desktop/phone
Remove unnecessary style indirection
Fix build errors
* [A] Add PlatformConfigurationExtensions
* SetSoftInputMode test page
* [A] SetSoftInputMode
Known issue: Status bar color does not work in AdjustResize mode
* [Core] Add PS Blur
* [iOS] Configure renderer for blur
* Add test page
* Move to blur VisualElement for broader support
* Move test pages to gallery
* Update docs
* Use lazy initializer for PlatformConfigurationRegistry
Diffstat (limited to 'Xamarin.Forms.Controls')
11 files changed, 645 insertions, 2 deletions
diff --git a/Xamarin.Forms.Controls/App.cs b/Xamarin.Forms.Controls/App.cs index af7e999c..c6480040 100644 --- a/Xamarin.Forms.Controls/App.cs +++ b/Xamarin.Forms.Controls/App.cs @@ -3,7 +3,8 @@ using System.Collections.Generic; using System.IO; using System.Reflection; using System.Threading.Tasks; -using Xamarin.Forms.Controls.Issues; +using Xamarin.Forms.PlatformConfiguration; +using Xamarin.Forms.PlatformConfiguration.WindowsSpecific; namespace Xamarin.Forms.Controls { @@ -34,7 +35,6 @@ namespace Xamarin.Forms.Controls protected override void OnAppLinkRequestReceived(Uri uri) { - var appDomain = "http://" + AppName.ToLowerInvariant() + "/"; if (!uri.ToString().ToLowerInvariant().StartsWith(appDomain)) diff --git a/Xamarin.Forms.Controls/CoreGallery.cs b/Xamarin.Forms.Controls/CoreGallery.cs index dc3217ca..7986a45c 100644 --- a/Xamarin.Forms.Controls/CoreGallery.cs +++ b/Xamarin.Forms.Controls/CoreGallery.cs @@ -220,6 +220,7 @@ namespace Xamarin.Forms.Controls public CorePageView (Page rootPage, NavigationBehavior navigationBehavior = NavigationBehavior.PushAsync) { var pages = new List<Page> { + new PlatformSpecificsGallery() {Title = "Platform Specifics"}, new AppLinkPageGallery {Title = "App Link Page Gallery"}, new NestedNativeControlGalleryPage {Title = "Nested Native Controls Gallery"}, new CellForceUpdateSizeGalleryPage {Title = "Cell Force Update Size Gallery"}, diff --git a/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/ApplicationAndroid.cs b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/ApplicationAndroid.cs new file mode 100644 index 00000000..4290adff --- /dev/null +++ b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/ApplicationAndroid.cs @@ -0,0 +1,40 @@ +using System.Windows.Input; +using Xamarin.Forms.PlatformConfiguration; +using Xamarin.Forms.PlatformConfiguration.AndroidSpecific; + +namespace Xamarin.Forms.Controls.GalleryPages.PlatformSpecificsGalleries +{ + public class ApplicationAndroid : ContentPage + { + public ApplicationAndroid(ICommand restore) + { + var restoreButton = new Button { Text = "Back To Gallery" }; + restoreButton.Clicked += (sender, args) => restore.Execute(null); + + var button1 = GetButton(WindowSoftInputModeAdjust.Pan); + var button2 = GetButton(WindowSoftInputModeAdjust.Resize); + var buttons = new StackLayout { Orientation = StackOrientation.Horizontal, Children = { button1, button2 }, VerticalOptions = LayoutOptions.Start }; + var entry = new Entry { Text = "1", VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.StartAndExpand }; + var layout = new RelativeLayout + { + VerticalOptions = LayoutOptions.StartAndExpand, + HorizontalOptions = LayoutOptions.Center, + }; + layout.Children.Add(buttons, yConstraint: Xamarin.Forms.Constraint.RelativeToParent(parent => { return parent.Y; })); + layout.Children.Add(entry, yConstraint: Xamarin.Forms.Constraint.RelativeToParent(parent => { return parent.Height - 100; })); + + Content = layout; + Title = "Application Features"; + } + + static Button GetButton(WindowSoftInputModeAdjust value) + { + var button = new Button { Text = value.ToString(), Margin = 20 }; + button.Clicked += (sender, args) => + { + Application.Current.On<Android>().UseWindowSoftInputModeAdjust(value); + }; + return button; + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/MasterDetailPageWindows.cs b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/MasterDetailPageWindows.cs new file mode 100644 index 00000000..d862c167 --- /dev/null +++ b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/MasterDetailPageWindows.cs @@ -0,0 +1,192 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Windows.Input; +using Xamarin.Forms.PlatformConfiguration; +using Xamarin.Forms.PlatformConfiguration.WindowsSpecific; +using static Xamarin.Forms.Controls.GalleryPages.PlatformSpecificsGalleries.WindowsPlatformSpecificsGalleryHelpers; + +namespace Xamarin.Forms.Controls.GalleryPages.PlatformSpecificsGalleries +{ + public class MasterDetailPageWindows : MasterDetailPage + { + public MasterDetailPageWindows(ICommand restore) + { + On<Windows>() + .SetCollapseStyle(CollapseStyle.Partial); + MasterBehavior = MasterBehavior.Popover; + + var master = new ContentPage { Title = "Master Detail Page" }; + var masterContent = new StackLayout { Spacing = 10, Margin = new Thickness(0, 10, 5, 0) }; + var detail = new ContentPage { Title = "This is the detail page's Title" }; + + // Build the navigation pane items + var navItems = new List<NavItem> + { + new NavItem("Display Alert", "\uE171", new Command(() => DisplayAlert("Alert", "This is an alert", "OK"))), + new NavItem("Return To Gallery", "\uE106", restore), + new NavItem("Save", "\uE105", new Command(() => DisplayAlert("Save", "Fake save dialog", "OK"))), + new NavItem("Audio", "\uE189", new Command(() => DisplayAlert("Audio", "Never gonna give you up...", "OK"))), + new NavItem("Set Detail to Navigation Page", "\uE16F", new Command(() => Detail = CreateNavigationPage())), + new NavItem("Set Detail to Content Page", "\uE160", new Command(() => Detail = detail)), + }; + + var navList = new NavList(navItems); + + // And add them to the navigation pane's content + masterContent.Children.Add(navList); + master.Content = masterContent; + + var detailContent = new StackLayout { VerticalOptions = LayoutOptions.Fill, HorizontalOptions = LayoutOptions.Fill }; + detailContent.Children.Add(new Label + { + Text = "Platform Features", + FontAttributes = FontAttributes.Bold, + HorizontalTextAlignment = TextAlignment.Center, + VerticalTextAlignment = TextAlignment.Center + }); + + detailContent.Children.Add(CreateCollapseStyleChanger(this)); + detailContent.Children.Add(CreateToolbarPlacementChanger(this)); + detailContent.Children.Add(CreateCollapseWidthAdjuster(this)); + detailContent.Children.Add(CreateAddRemoveToolBarItemButtons(this)); + + detail.Content = detailContent; + + Master = master; + + AddToolBarItems(this); + + Detail = detail; + } + + static Layout CreateCollapseStyleChanger(MasterDetailPage page) + { + Type enumType = typeof(CollapseStyle); + + return CreateChanger(enumType, + Enum.GetName(enumType, page.On<Windows>().GetCollapseStyle()), + picker => + { + page.On<Windows>().SetCollapseStyle((CollapseStyle)Enum.Parse(enumType, picker.Items[picker.SelectedIndex])); + }, + "Select Collapse Style"); + } + + static Layout CreateCollapseWidthAdjuster(MasterDetailPage page) + { + var adjustCollapseWidthLabel = new Label + { + Text = "Adjust Collapsed Width", + VerticalTextAlignment = TextAlignment.Center, + VerticalOptions = LayoutOptions.Center + }; + var adjustCollapseWidthEntry = new Entry { Text = page.On<Windows>().CollapsedPaneWidth().ToString() }; + var adjustCollapseWidthButton = new Button { Text = "Change", BackgroundColor = Color.Gray }; + adjustCollapseWidthButton.Clicked += (sender, args) => + { + double newWidth; + if (double.TryParse(adjustCollapseWidthEntry.Text, out newWidth)) + { + page.On<Windows>().CollapsedPaneWidth(newWidth); + } + }; + + var adjustCollapsedWidthSection = new StackLayout + { + HorizontalOptions = LayoutOptions.Center, + Orientation = StackOrientation.Horizontal, + Children = { adjustCollapseWidthLabel, adjustCollapseWidthEntry, adjustCollapseWidthButton } + }; + + return adjustCollapsedWidthSection; + } + + public class NavItem + { + public NavItem(string text, string icon, ICommand command) + { + Text = text; + Icon = icon; + Command = command; + } + + public ICommand Command { get; set; } + + public string Icon { get; set; } + + public string Text { get; set; } + } + + public class NavList : ListView + { + public NavList(IEnumerable<NavItem> items) + { + ItemsSource = items; + ItemTapped += (sender, args) => (args.Item as NavItem)?.Command.Execute(null); + + ItemTemplate = new DataTemplate(() => + { + var grid = new Grid(); + grid.ColumnDefinitions.Add(new ColumnDefinition { Width = 48 }); + grid.ColumnDefinitions.Add(new ColumnDefinition { Width = 200 }); + + grid.Margin = new Thickness(0, 10, 0, 10); + + var text = new Label + { + VerticalOptions = LayoutOptions.Fill + }; + text.SetBinding(Label.TextProperty, "Text"); + + var glyph = new Label + { + FontFamily = "Segoe MDL2 Assets", + FontSize = 24, + HorizontalTextAlignment = TextAlignment.Center + }; + + glyph.SetBinding(Label.TextProperty, "Icon"); + + grid.Children.Add(glyph); + grid.Children.Add(text); + + Grid.SetColumn(glyph, 0); + Grid.SetColumn(text, 1); + + grid.WidthRequest = 48; + + var cell = new ViewCell + { + View = grid + }; + + return cell; + }); + } + } + + static NavigationPage CreateNavigationPage() + { + var page = new NavigationPage { Title = "This is the Navigation Page Title" }; + + page.PushAsync(CreateNavSubPage()); + + return page; + } + + static ContentPage CreateNavSubPage() + { + var page = new ContentPage(); + + var label = new Label { Text = "This is content in a nav page" }; + var button = new Button() { Text = "Push Another Page"}; + + button.Clicked += (sender, args) => page.Navigation.PushAsync(CreateNavSubPage()); + + page.Content = new StackLayout { Children = { label, button } }; + + return page; + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/NavigationPageWindows.cs b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/NavigationPageWindows.cs new file mode 100644 index 00000000..1143678b --- /dev/null +++ b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/NavigationPageWindows.cs @@ -0,0 +1,68 @@ +using System.Windows.Input; + +namespace Xamarin.Forms.Controls.GalleryPages.PlatformSpecificsGalleries +{ + public class NavigationPageWindows : NavigationPage + { + public NavigationPageWindows(ICommand restore) + { + PushAsync(CreateRoot(restore)); + WindowsPlatformSpecificsGalleryHelpers.AddToolBarItems(this); + } + + ContentPage CreateRoot(ICommand restore) + { + var page = new ContentPage { Title = "Content Page Title" }; + + var content = new StackLayout + { + VerticalOptions = LayoutOptions.Fill, + HorizontalOptions = LayoutOptions.Fill + }; + content.Children.Add(new Label + { + Text = "Navigation Page Windows Features", + FontAttributes = FontAttributes.Bold, + HorizontalTextAlignment = TextAlignment.Center, + VerticalTextAlignment = TextAlignment.Center + }); + + content.Children.Add(WindowsPlatformSpecificsGalleryHelpers.CreateToolbarPlacementChanger(this)); + content.Children.Add(WindowsPlatformSpecificsGalleryHelpers.CreateAddRemoveToolBarItemButtons(this)); + + var restoreButton = new Button { Text = "Back To Gallery" }; + restoreButton.Clicked += (sender, args) => restore.Execute(null); + content.Children.Add(restoreButton); + + var navButton = new Button { Text = "Push Page (with no title)" }; + navButton.Clicked += (sender, args) => PushAsync(CreatePageWithNoTitle()); + content.Children.Add(navButton); + + page.Content = content; + + return page; + } + + ContentPage CreatePageWithNoTitle() + { + var page = new ContentPage { }; + + var content = new StackLayout + { + VerticalOptions = LayoutOptions.Fill, + HorizontalOptions = LayoutOptions.Fill + }; + content.Children.Add(new Label + { + Text = "Page 2", + FontAttributes = FontAttributes.Bold, + HorizontalTextAlignment = TextAlignment.Center, + VerticalTextAlignment = TextAlignment.Center + }); + + page.Content = content; + + return page; + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/NavigationPageiOS.cs b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/NavigationPageiOS.cs new file mode 100644 index 00000000..92f278bb --- /dev/null +++ b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/NavigationPageiOS.cs @@ -0,0 +1,40 @@ +using System.Windows.Input; +using Xamarin.Forms.PlatformConfiguration; +using Xamarin.Forms.PlatformConfiguration.iOSSpecific; + +namespace Xamarin.Forms.Controls.GalleryPages.PlatformSpecificsGalleries +{ + public class NavigationPageiOS : NavigationPage + { + public static NavigationPageiOS Create(ICommand restore) + { + var restoreButton = new Button { Text = "Back To Gallery" }; + restoreButton.Clicked += (sender, args) => restore.Execute(null); + + var translucentToggleButton = new Button { Text = "Toggle Translucent NavBar" }; + + var content = new ContentPage + { + Title = "Navigation Page Features", + Content = new StackLayout + { + VerticalOptions = LayoutOptions.Center, + HorizontalOptions = LayoutOptions.Center, + Children = { translucentToggleButton, restoreButton } + } + }; + + var navPage = new NavigationPageiOS(content, restore); + + translucentToggleButton.Clicked += (sender, args) => navPage.On<iOS>().SetIsNavigationBarTranslucent(!navPage.On<iOS>().IsNavigationBarTranslucent()); + + return navPage; + } + + public NavigationPageiOS(Page root, ICommand restore) : base(root) + { + BackgroundColor = Color.Pink; + On<iOS>().EnableTranslucentNavigationBar(); + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/TabbedPageWindows.cs b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/TabbedPageWindows.cs new file mode 100644 index 00000000..11b5d8c4 --- /dev/null +++ b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/TabbedPageWindows.cs @@ -0,0 +1,65 @@ +using System.Windows.Input; + +namespace Xamarin.Forms.Controls.GalleryPages.PlatformSpecificsGalleries +{ + public class TabbedPageWindows : TabbedPage + { + public TabbedPageWindows(ICommand restore) + { + Children.Add(CreateFirstPage(restore)); + Children.Add(CreateSecondPage()); + WindowsPlatformSpecificsGalleryHelpers.AddToolBarItems(this); + } + + ContentPage CreateFirstPage(ICommand restore) + { + var page = new ContentPage { Title = "Content Page Title" }; + + var content = new StackLayout + { + VerticalOptions = LayoutOptions.Fill, + HorizontalOptions = LayoutOptions.Fill + }; + content.Children.Add(new Label + { + Text = "Tabbed Page Windows Features", + FontAttributes = FontAttributes.Bold, + HorizontalTextAlignment = TextAlignment.Center, + VerticalTextAlignment = TextAlignment.Center + }); + + content.Children.Add(WindowsPlatformSpecificsGalleryHelpers.CreateToolbarPlacementChanger(this)); + content.Children.Add(WindowsPlatformSpecificsGalleryHelpers.CreateAddRemoveToolBarItemButtons(this)); + + var restoreButton = new Button { Text = "Back To Gallery" }; + restoreButton.Clicked += (sender, args) => restore.Execute(null); + content.Children.Add(restoreButton); + + page.Content = content; + + return page; + } + + static Page CreateSecondPage() + { + var cp = new ContentPage { Title = "Second Content Page" }; + + var content = new StackLayout + { + VerticalOptions = LayoutOptions.Fill, + HorizontalOptions = LayoutOptions.Fill + }; + content.Children.Add(new Label + { + Text = "Page 2", + FontAttributes = FontAttributes.Bold, + HorizontalTextAlignment = TextAlignment.Center, + VerticalTextAlignment = TextAlignment.Center + }); + + cp.Content = content; + + return cp; + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/VisualElementiOS.cs b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/VisualElementiOS.cs new file mode 100644 index 00000000..410d9157 --- /dev/null +++ b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/VisualElementiOS.cs @@ -0,0 +1,34 @@ +using System.Windows.Input; +using Xamarin.Forms.PlatformConfiguration; +using Xamarin.Forms.PlatformConfiguration.iOSSpecific; + +namespace Xamarin.Forms.Controls.GalleryPages.PlatformSpecificsGalleries +{ + public class VisualElementiOS : ContentPage + { + public VisualElementiOS(ICommand restore) + { + var restoreButton = new Button { Text = "Back To Gallery" }; + restoreButton.Clicked += (sender, args) => restore.Execute(null); + + var image = new Image { Source = ImageSource.FromFile("crimson.jpg") }; + var box = new BoxView { HeightRequest = 300, WidthRequest = 600 }; + box.On<iOS>().UseBlurEffect(BlurEffectStyle.Light); + Button button1 = GetButton(box, BlurEffectStyle.None); + Button button2 = GetButton(box, BlurEffectStyle.ExtraLight); + Button button3 = GetButton(box, BlurEffectStyle.Light); + Button button4 = GetButton(box, BlurEffectStyle.Dark); + var buttons = new StackLayout { Orientation = StackOrientation.Horizontal, Children = { button1, button2, button3, button4 } }; + + Content = new StackLayout { Children = { buttons, new AbsoluteLayout { Children = { image, box } } } }; + Title = "Visual Element Features"; + } + + Button GetButton(BoxView box, BlurEffectStyle value) + { + var button1 = new Button { Text = value.ToString(), Margin = 25 }; + button1.Clicked += (s, e) => { box.On<iOS>().UseBlurEffect(value); }; + return button1; + } + } +} diff --git a/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/WindowsPlatformSpecificsGalleryHelpers.cs b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/WindowsPlatformSpecificsGalleryHelpers.cs new file mode 100644 index 00000000..08371919 --- /dev/null +++ b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/WindowsPlatformSpecificsGalleryHelpers.cs @@ -0,0 +1,141 @@ +using System; +using System.Linq; +using Xamarin.Forms.PlatformConfiguration; +using Xamarin.Forms.PlatformConfiguration.WindowsSpecific; + +namespace Xamarin.Forms.Controls.GalleryPages.PlatformSpecificsGalleries +{ + internal static class WindowsPlatformSpecificsGalleryHelpers + { + const string CommandBarActionTitle = "Hey!"; + const string CommandBarActionMessage = "Command Bar Item Clicked"; + const string CommandBarActionDismiss = "OK"; + + public static void AddToolBarItems(Page page) + { + Action action = () => page.DisplayAlert(CommandBarActionTitle, CommandBarActionMessage, CommandBarActionDismiss); + + var tb1 = new ToolbarItem("Primary 1", "coffee.png", action, ToolbarItemOrder.Primary) + { + IsEnabled = true, + AutomationId = "toolbaritem_primary1" + }; + + var tb2 = new ToolbarItem("Primary 2", "coffee.png", action, ToolbarItemOrder.Primary) + { + IsEnabled = true, + AutomationId = "toolbaritem_primary2" + }; + + var tb3 = new ToolbarItem("Seconday 1", "coffee.png", action, ToolbarItemOrder.Secondary) + { + IsEnabled = true, + AutomationId = "toolbaritem_secondary3" + }; + + var tb4 = new ToolbarItem("Secondary 2", "coffee.png", action, ToolbarItemOrder.Secondary) + { + IsEnabled = true, + AutomationId = "toolbaritem_secondary4" + }; + + page.ToolbarItems.Add(tb1); + page.ToolbarItems.Add(tb2); + page.ToolbarItems.Add(tb3); + page.ToolbarItems.Add(tb4); + } + + public static Layout CreateChanger(Type enumType, string defaultOption, Action<Picker> selectedIndexChanged, string label) + { + var picker = new Picker(); + string[] options = Enum.GetNames(enumType); + foreach (string option in options) + { + picker.Items.Add(option); + } + + picker.SelectedIndex = options.IndexOf(defaultOption); + + picker.SelectedIndexChanged += (sender, args) => + { + selectedIndexChanged(picker); + }; + + var changerLabel = new Label { Text = label, VerticalOptions = LayoutOptions.Center }; + + var layout = new Grid + { + HorizontalOptions = LayoutOptions.Center, + ColumnDefinitions = new ColumnDefinitionCollection + { + new ColumnDefinition { Width = 150 }, + new ColumnDefinition { Width = 100 } + }, + Children = { changerLabel, picker } + }; + + Grid.SetColumn(changerLabel, 0); + Grid.SetColumn(picker, 1); + + return layout; + } + + public static Layout CreateToolbarPlacementChanger(Page page) + { + Type enumType = typeof(ToolbarPlacement); + + return CreateChanger(enumType, + Enum.GetName(enumType, page.On<Windows>().GetToolbarPlacement()), + picker => + { + page.On<Windows>().SetToolbarPlacement((ToolbarPlacement)Enum.Parse(enumType, picker.Items[picker.SelectedIndex])); + }, "Select Toolbar Placement"); + } + + public static Layout CreateAddRemoveToolBarItemButtons(Page page) + { + var layout = new StackLayout { Orientation = StackOrientation.Vertical, HorizontalOptions = LayoutOptions.Center }; + layout.Children.Add(new Label { Text = "Toolbar Items:" }); + + var buttonLayout = new StackLayout + { + Orientation = StackOrientation.Horizontal, + HorizontalOptions = LayoutOptions.Center + }; + + layout.Children.Add(buttonLayout); + + var addPrimary = new Button { Text = "Add Primary", BackgroundColor = Color.Gray }; + var addSecondary = new Button { Text = "Add Secondary", BackgroundColor = Color.Gray }; + var remove = new Button { Text = "Remove", BackgroundColor = Color.Gray }; + + buttonLayout.Children.Add(addPrimary); + buttonLayout.Children.Add(addSecondary); + buttonLayout.Children.Add(remove); + + Action action = () => page.DisplayAlert(CommandBarActionTitle, CommandBarActionMessage, CommandBarActionDismiss); + + addPrimary.Clicked += (sender, args) => + { + int index = page.ToolbarItems.Count(item => item.Order == ToolbarItemOrder.Primary) + 1; + page.ToolbarItems.Add(new ToolbarItem($"Primary {index}", "coffee.png", action, ToolbarItemOrder.Primary)); + }; + + addSecondary.Clicked += (sender, args) => + { + int index = page.ToolbarItems.Count(item => item.Order == ToolbarItemOrder.Secondary) + 1; + page.ToolbarItems.Add(new ToolbarItem($"Secondary {index}", "coffee.png", action, ToolbarItemOrder.Secondary)); + }; + + remove.Clicked += (sender, args) => + { + if (page.ToolbarItems.Any()) + { + page.ToolbarItems.RemoveAt(0); + } + }; + + return layout; + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGallery.cs b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGallery.cs new file mode 100644 index 00000000..67465da1 --- /dev/null +++ b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGallery.cs @@ -0,0 +1,54 @@ +using Xamarin.Forms.Controls.GalleryPages.PlatformSpecificsGalleries; + +namespace Xamarin.Forms.Controls +{ + public class PlatformSpecificsGallery : ContentPage + { + Page _originalRoot; + + public PlatformSpecificsGallery() + { + var mdpWindowsButton = new Button { Text = "Master Detail Page (Windows)" }; + var npWindowsButton = new Button { Text = "Navigation Page (Windows)" }; + var tbWindowsButton = new Button { Text = "Tabbed Page (Windows)" }; + var navpageiOSButton = new Button() { Text = "Navigation Page (iOS)" }; + var viselemiOSButton = new Button() { Text = "Visual Element (iOS)" }; + var appAndroidButton = new Button() { Text = "Application (Android)" }; + + mdpWindowsButton.Clicked += (sender, args) => { SetRoot(new MasterDetailPageWindows(new Command(RestoreOriginal))); }; + npWindowsButton.Clicked += (sender, args) => { SetRoot(new NavigationPageWindows(new Command(RestoreOriginal))); }; + tbWindowsButton.Clicked += (sender, args) => { SetRoot(new TabbedPageWindows(new Command(RestoreOriginal))); }; + navpageiOSButton.Clicked += (sender, args) => { SetRoot(NavigationPageiOS.Create(new Command(RestoreOriginal))); }; + viselemiOSButton.Clicked += (sender, args) => { SetRoot(new VisualElementiOS(new Command(RestoreOriginal))); }; + appAndroidButton.Clicked += (sender, args) => { SetRoot(new ApplicationAndroid(new Command(RestoreOriginal))); }; + + Content = new StackLayout + { + Children = { mdpWindowsButton, npWindowsButton, tbWindowsButton, navpageiOSButton, viselemiOSButton, appAndroidButton } + }; + } + + void SetRoot(Page page) + { + var app = Application.Current as App; + if (app == null) + { + return; + } + + _originalRoot = app.MainPage; + app.SetMainPage(page); + } + + void RestoreOriginal() + { + if (_originalRoot == null) + { + return; + } + + var app = Application.Current as App; + app?.SetMainPage(_originalRoot); + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj b/Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj index ade7cd16..825d157d 100644 --- a/Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj +++ b/Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj @@ -99,8 +99,16 @@ <DependentUpon>ControlTemplateXamlPage.xaml</DependentUpon> </Compile> <Compile Include="GalleryPages\LayoutPerformanceGallery.cs" /> + <Compile Include="GalleryPages\PlatformSpecificsGalleries\MasterDetailPageWindows.cs" /> <Compile Include="GalleryPages\NavigationPropertiesGallery.cs" /> <Compile Include="ControlGalleryPages\ListViewSelectionColor.cs" /> + <Compile Include="GalleryPages\PlatformSpecificsGalleries\NavigationPageiOS.cs" /> + <Compile Include="GalleryPages\PlatformSpecificsGalleries\NavigationPageWindows.cs" /> + <Compile Include="GalleryPages\PlatformSpecificsGalleries\ApplicationAndroid.cs" /> + <Compile Include="GalleryPages\PlatformSpecificsGalleries\TabbedPageWindows.cs" /> + <Compile Include="GalleryPages\PlatformSpecificsGalleries\VisualElementiOS.cs" /> + <Compile Include="GalleryPages\PlatformSpecificsGalleries\WindowsPlatformSpecificsGalleryHelpers.cs" /> + <Compile Include="GalleryPages\PlatformSpecificsGallery.cs" /> <Compile Include="LegacyRepro\Page1.xaml.cs"> <DependentUpon>Page1.xaml</DependentUpon> </Compile> |