diff options
author | Kangho Hur <kangho.hur@samsung.com> | 2017-03-24 14:29:22 +0900 |
---|---|---|
committer | Kangho Hur <kangho.hur@samsung.com> | 2017-03-24 14:47:36 +0900 |
commit | 161a8e0f544b44f848d4c68ac9637d3a8b3f2520 (patch) | |
tree | 9a61043f0e27ef4f9855fcc1fc70693b12f10f4f /Xamarin.Forms.Platform.WinRT | |
parent | 20daaa5702a27d1a9c7cf9dfacfdfa254ac0e5e3 (diff) | |
download | xamarin-forms-161a8e0f544b44f848d4c68ac9637d3a8b3f2520.tar.gz xamarin-forms-161a8e0f544b44f848d4c68ac9637d3a8b3f2520.tar.bz2 xamarin-forms-161a8e0f544b44f848d4c68ac9637d3a8b3f2520.zip |
Clean sync with 2.3.4-2
Change-Id: I6a7423d2690a1c30f46e0c128d9504a2464f8f0b
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT')
14 files changed, 587 insertions, 564 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs b/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs index acc41db3..aff11963 100644 --- a/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs +++ b/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.ComponentModel; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; @@ -8,7 +8,6 @@ using Xamarin.Forms.Internals; using WThickness = Windows.UI.Xaml.Thickness; using WButton = Windows.UI.Xaml.Controls.Button; using WImage = Windows.UI.Xaml.Controls.Image; -using Windows.UI.Xaml.Input; #if WINDOWS_UWP @@ -32,7 +31,6 @@ namespace Xamarin.Forms.Platform.WinRT { var button = new FormsButton(); button.Click += OnButtonClick; - button.AddHandler(PointerPressedEvent, new PointerEventHandler(OnPointerPressed), true); SetNativeControl(button); } @@ -101,16 +99,12 @@ namespace Xamarin.Forms.Platform.WinRT void OnButtonClick(object sender, RoutedEventArgs e) { - ((IButtonController)Element)?.SendReleased(); - ((IButtonController)Element)?.SendClicked(); + Button buttonView = Element; + if (buttonView != null) + ((IButtonController)buttonView).SendClicked(); } - void OnPointerPressed(object sender, RoutedEventArgs e) - { - ((IButtonController)Element)?.SendPressed(); - } - - void UpdateBackground() + void UpdateBackground() { Control.BackgroundColor = Element.BackgroundColor != Color.Default ? Element.BackgroundColor.ToBrush() : (Brush)Windows.UI.Xaml.Application.Current.Resources["ButtonBackgroundThemeBrush"]; } diff --git a/Xamarin.Forms.Platform.WinRT/CarouselPageRenderer.cs b/Xamarin.Forms.Platform.WinRT/CarouselPageRenderer.cs index 33e09399..11f4e09d 100644 --- a/Xamarin.Forms.Platform.WinRT/CarouselPageRenderer.cs +++ b/Xamarin.Forms.Platform.WinRT/CarouselPageRenderer.cs @@ -70,11 +70,6 @@ namespace Xamarin.Forms.Platform.WinRT return new SizeRequest(result); } - UIElement IVisualElementRenderer.GetNativeElement() - { - return null; - } - public void SetElement(VisualElement element) { var newPage = element as CarouselPage; diff --git a/Xamarin.Forms.Platform.WinRT/FrameworkElementExtensions.cs b/Xamarin.Forms.Platform.WinRT/FrameworkElementExtensions.cs index 6affa169..f94f3d62 100644 --- a/Xamarin.Forms.Platform.WinRT/FrameworkElementExtensions.cs +++ b/Xamarin.Forms.Platform.WinRT/FrameworkElementExtensions.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Reflection; diff --git a/Xamarin.Forms.Platform.WinRT/IVisualElementRenderer.cs b/Xamarin.Forms.Platform.WinRT/IVisualElementRenderer.cs index abae812e..4db9c1a6 100644 --- a/Xamarin.Forms.Platform.WinRT/IVisualElementRenderer.cs +++ b/Xamarin.Forms.Platform.WinRT/IVisualElementRenderer.cs @@ -18,9 +18,6 @@ namespace Xamarin.Forms.Platform.WinRT event EventHandler<VisualElementChangedEventArgs> ElementChanged; SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint); - void SetElement(VisualElement element); - - UIElement GetNativeElement(); } }
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs b/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs index 031e2cf3..db581d52 100644 --- a/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs +++ b/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs @@ -77,6 +77,9 @@ namespace Xamarin.Forms.Platform.WinRT // and prevented from bubbling up) rather than ListView.ItemClick List.Tapped += ListOnTapped; + // We also want to watch for the Enter key being pressed for selection + List.KeyUp += OnKeyPressed; + List.SelectionChanged += OnControlSelectionChanged; List.SetBinding(ItemsControl.ItemsSourceProperty, ""); @@ -138,6 +141,7 @@ namespace Xamarin.Forms.Platform.WinRT if (List != null) { List.Tapped -= ListOnTapped; + List.KeyUp -= OnKeyPressed; List.SelectionChanged -= OnControlSelectionChanged; @@ -504,6 +508,17 @@ namespace Xamarin.Forms.Platform.WinRT #endif } + void OnKeyPressed(object sender, KeyRoutedEventArgs e) + { + if (e.Key == VirtualKey.Enter) + { + if (Element.SelectedItem != null && Element.SelectedItem != List.SelectedItem) + { + ((IElementController)Element).SetValueFromRenderer(ListView.SelectedItemProperty, List.SelectedItem); + } + } + } + void OnControlSelectionChanged(object sender, SelectionChangedEventArgs e) { RestorePreviousSelectedVisual(); @@ -525,10 +540,6 @@ namespace Xamarin.Forms.Platform.WinRT } } #endif - - // A11y: Tapped event will not be routed when Narrator is active - // Also handles keyboard selection - SelectElementItem(); } FrameworkElement FindElement(object cell) @@ -542,15 +553,6 @@ namespace Xamarin.Forms.Platform.WinRT return null; } - void SelectElementItem() - { - if (List.SelectedItem != null && Element.SelectedItem != List.SelectedItem) - { - ((IElementController)Element).SetValueFromRenderer(ListView.SelectedItemProperty, List?.SelectedItem); - OnElementItemSelected(null, new SelectedItemChangedEventArgs(Element?.SelectedItem)); - } - } - #if WINDOWS_UWP void RestorePreviousSelectedVisual() { diff --git a/Xamarin.Forms.Platform.WinRT/MasterDetailPageRenderer.cs b/Xamarin.Forms.Platform.WinRT/MasterDetailPageRenderer.cs index dcef680e..414870cd 100644 --- a/Xamarin.Forms.Platform.WinRT/MasterDetailPageRenderer.cs +++ b/Xamarin.Forms.Platform.WinRT/MasterDetailPageRenderer.cs @@ -94,11 +94,6 @@ namespace Xamarin.Forms.Platform.WinRT public event EventHandler<VisualElementChangedEventArgs> ElementChanged; - UIElement IVisualElementRenderer.GetNativeElement() - { - return null; - } - public SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint) { return new SizeRequest(new Size(Device.Info.ScaledScreenSize.Width, Device.Info.ScaledScreenSize.Height)); diff --git a/Xamarin.Forms.Platform.WinRT/NavigationPageRenderer.cs b/Xamarin.Forms.Platform.WinRT/NavigationPageRenderer.cs index 5229fdcb..d6f45420 100644 --- a/Xamarin.Forms.Platform.WinRT/NavigationPageRenderer.cs +++ b/Xamarin.Forms.Platform.WinRT/NavigationPageRenderer.cs @@ -13,23 +13,35 @@ using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Media.Animation; using Xamarin.Forms.Internals; +using Xamarin.Forms.PlatformConfiguration.WindowsSpecific; #if WINDOWS_UWP +using Windows.UI.Xaml.Data; using Windows.UI.Core; + +#endif + +#if WINDOWS_UWP + namespace Xamarin.Forms.Platform.UWP #else namespace Xamarin.Forms.Platform.WinRT #endif { - public partial class NavigationPageRenderer : IVisualElementRenderer, ITitleProvider, IToolbarProvider + public class NavigationPageRenderer : IVisualElementRenderer, ITitleProvider, IToolbarProvider +#if WINDOWS_UWP + , IToolBarForegroundBinder +#endif { PageControl _container; Page _currentPage; Page _previousPage; bool _disposed; - +#if WINDOWS_UWP + SystemNavigationManager _navManager; +#endif MasterDetailPage _parentMasterDetailPage; TabbedPage _parentTabbedPage; bool _showTitle = true; @@ -137,15 +149,10 @@ namespace Xamarin.Forms.Platform.WinRT return new SizeRequest(result); } - UIElement IVisualElementRenderer.GetNativeElement() - { - return null; - } - public void SetElement(VisualElement element) { if (element != null && !(element is NavigationPage)) - throw new ArgumentException("Element must be a Page", nameof(element)); + throw new ArgumentException("Element must be a Page", "element"); NavigationPage oldElement = Element; Element = (NavigationPage)element; @@ -206,11 +213,8 @@ namespace Xamarin.Forms.Platform.WinRT protected void Dispose(bool disposing) { - if (_disposed || !disposing) - { + if (!disposing || _disposed) return; - } - PageController?.SendDisappearing(); _disposed = true; @@ -245,8 +249,11 @@ namespace Xamarin.Forms.Platform.WinRT Brush GetBarBackgroundBrush() { - object defaultColor = GetDefaultColor(); - +#if WINDOWS_UWP + object defaultColor = Windows.UI.Xaml.Application.Current.Resources["SystemControlBackgroundChromeMediumLowBrush"]; +#else + object defaultColor = Windows.UI.Xaml.Application.Current.Resources["ApplicationPageBackgroundThemeBrush"]; +#endif if (Element.BarBackgroundColor.IsDefault && defaultColor != null) return (Brush)defaultColor; return Element.BarBackgroundColor.ToBrush(); @@ -260,11 +267,28 @@ namespace Xamarin.Forms.Platform.WinRT return Element.BarTextColor.ToBrush(); } + // TODO EZH Why don't this and GetToolBarProvider ever get called on either platform? + Task<CommandBar> GetCommandBarAsync() + { + var platform = (Platform)Element.Platform; + IToolbarProvider toolbarProvider = platform.GetToolbarProvider(); + if (toolbarProvider == null) + return Task.FromResult<CommandBar>(null); + + return toolbarProvider.GetCommandBarAsync(); + } + bool GetIsNavBarPossible() { return _showTitle; } + IToolbarProvider GetToolbarProvider() + { + var platform = (Platform)Element.Platform; + return platform.GetToolbarProvider(); + } + void LookupRelevantParents() { IEnumerable<Page> parentPages = Element.GetParentPages(); @@ -284,9 +308,16 @@ namespace Xamarin.Forms.Platform.WinRT _parentTabbedPage.PropertyChanged += MultiPagePropertyChanged; if (_parentMasterDetailPage != null) _parentMasterDetailPage.PropertyChanged += MultiPagePropertyChanged; +#if WINDOWS_UWP + ((ITitleProvider)this).ShowTitle = _parentTabbedPage == null && _parentMasterDetailPage == null; - UpdateShowTitle(); - + +#else + if (Device.Idiom == TargetIdiom.Phone && _parentTabbedPage != null) + ((ITitleProvider)this).ShowTitle = false; + else + ((ITitleProvider)this).ShowTitle = true; +#endif UpdateTitleOnParents(); } @@ -324,10 +355,8 @@ namespace Xamarin.Forms.Platform.WinRT UpdateNavigationBarBackground(); else if (e.PropertyName == Page.PaddingProperty.PropertyName) UpdatePadding(); -#if WINDOWS_UWP - else if (e.PropertyName == PlatformConfiguration.WindowsSpecific.Page.ToolbarPlacementProperty.PropertyName) + else if (e.PropertyName == PlatformConfiguration.WindowsSpecific.Page.ToolbarPlacementProperty.PropertyName) UpdateToolbarPlacement(); -#endif } void OnLoaded(object sender, RoutedEventArgs args) @@ -369,7 +398,7 @@ namespace Xamarin.Forms.Platform.WinRT void OnPopRequested(object sender, NavigationRequestedEventArgs e) { - var newCurrent = ((INavigationPageController)Element).Peek(1); + var newCurrent = (Page)PageController.InternalChildren[PageController.InternalChildren.Count - 2]; SetPage(newCurrent, e.Animated, true); } @@ -390,10 +419,8 @@ namespace Xamarin.Forms.Platform.WinRT void PushExistingNavigationStack() { - foreach (var page in ((INavigationPageController)Element).Pages) - { - SetPage(page, false, false); - } + for (int i = ((INavigationPageController)Element).StackCopy.Count - 1; i >= 0; i--) + SetPage(((INavigationPageController)Element).StackCopy.ElementAt(i), false, false); } void SetPage(Page page, bool isAnimated, bool isPopping) @@ -441,6 +468,19 @@ namespace Xamarin.Forms.Platform.WinRT _container.DataContext = page; } + void UpdateBackButton() + { + bool showBackButton = PageController.InternalChildren.Count > 1 && NavigationPage.GetHasBackButton(_currentPage); + _container.ShowBackButton = showBackButton; + +#if WINDOWS_UWP + if (_navManager != null) + { + _navManager.AppViewBackButtonVisibility = showBackButton ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed; + } +#endif + } + void UpdateBackButtonTitle() { string title = null; @@ -485,5 +525,74 @@ namespace Xamarin.Forms.Platform.WinRT { (this as ITitleProvider).BarForegroundBrush = GetBarForegroundBrush(); } + + void UpdateToolbarPlacement() + { +#if WINDOWS_UWP + if (_container == null) + { + return; + } + + _container.ToolbarPlacement = Element.OnThisPlatform().GetToolbarPlacement(); +#endif + } + +#pragma warning disable 1998 // considered for removal + async void UpdateTitleOnParents() +#pragma warning restore 1998 + { + if (Element == null) + return; + + ITitleProvider render = null; + if (_parentTabbedPage != null) + { + render = Platform.GetRenderer(_parentTabbedPage) as ITitleProvider; + if (render != null) + render.ShowTitle = (_parentTabbedPage.CurrentPage == Element) && NavigationPage.GetHasNavigationBar(_currentPage); + } + + if (_parentMasterDetailPage != null) + { + render = Platform.GetRenderer(_parentMasterDetailPage) as ITitleProvider; + if (render != null) + render.ShowTitle = (_parentMasterDetailPage.Detail == Element) && NavigationPage.GetHasNavigationBar(_currentPage); + } + + if (render != null && render.ShowTitle) + { + render.Title = _currentPage.Title; + render.BarBackgroundBrush = GetBarBackgroundBrush(); + render.BarForegroundBrush = GetBarForegroundBrush(); +#if WINDOWS_UWP + await (Element.Platform as Platform).UpdateToolbarItems(); +#endif + } + else if (_showTitle) + { +#if WINDOWS_UWP + await (Element.Platform as Platform).UpdateToolbarItems(); +#endif + } + } + +#if WINDOWS_UWP + public void BindForegroundColor(AppBar appBar) + { + SetAppBarForegroundBinding(appBar); + } + + public void BindForegroundColor(AppBarButton button) + { + SetAppBarForegroundBinding(button); + } + + void SetAppBarForegroundBinding(FrameworkElement element) + { + element.SetBinding(Control.ForegroundProperty, + new Windows.UI.Xaml.Data.Binding { Path = new PropertyPath("TitleBrush"), Source = _container, RelativeSource = new RelativeSource { Mode = RelativeSourceMode.TemplatedParent } }); + } +#endif } -} +}
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.WinRT/NavigationPageRendererWinRT.cs b/Xamarin.Forms.Platform.WinRT/NavigationPageRendererWinRT.cs deleted file mode 100644 index 1539d3aa..00000000 --- a/Xamarin.Forms.Platform.WinRT/NavigationPageRendererWinRT.cs +++ /dev/null @@ -1,57 +0,0 @@ -namespace Xamarin.Forms.Platform.WinRT -{ - public partial class NavigationPageRenderer - { - void UpdateShowTitle() - { - if (Device.Idiom == TargetIdiom.Phone && _parentTabbedPage != null) - ((ITitleProvider)this).ShowTitle = false; - else - ((ITitleProvider)this).ShowTitle = true; - } - - static object GetDefaultColor() - { - return Windows.UI.Xaml.Application.Current.Resources["ApplicationPageBackgroundThemeBrush"]; - } - - void UpdateBackButton() - { - bool showBackButton = PageController.InternalChildren.Count > 1 && NavigationPage.GetHasBackButton(_currentPage); - _container.ShowBackButton = showBackButton; - } - - void UpdateToolbarPlacement() - { - // Currently we don't support toolbar (CommandBar) placement on Windows 8.1 - } - - void UpdateTitleOnParents() - { - if (Element == null) - return; - - ITitleProvider render = null; - if (_parentTabbedPage != null) - { - render = Platform.GetRenderer(_parentTabbedPage) as ITitleProvider; - if (render != null) - render.ShowTitle = (_parentTabbedPage.CurrentPage == Element) && NavigationPage.GetHasNavigationBar(_currentPage); - } - - if (_parentMasterDetailPage != null) - { - render = Platform.GetRenderer(_parentMasterDetailPage) as ITitleProvider; - if (render != null) - render.ShowTitle = (_parentMasterDetailPage.Detail == Element) && NavigationPage.GetHasNavigationBar(_currentPage); - } - - if (render != null && render.ShowTitle) - { - render.Title = _currentPage.Title; - render.BarBackgroundBrush = GetBarBackgroundBrush(); - render.BarForegroundBrush = GetBarForegroundBrush(); - } - } - } -} diff --git a/Xamarin.Forms.Platform.WinRT/Platform.cs b/Xamarin.Forms.Platform.WinRT/Platform.cs index ec356e9a..2e30ac10 100644 --- a/Xamarin.Forms.Platform.WinRT/Platform.cs +++ b/Xamarin.Forms.Platform.WinRT/Platform.cs @@ -2,22 +2,39 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; + +using Windows.ApplicationModel.Core; +using Windows.UI; using Windows.UI.Popups; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; +using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Media.Animation; using Xamarin.Forms.Internals; #if WINDOWS_UWP +using Windows.Foundation; +using Windows.Foundation.Metadata; +using Windows.UI.Core; +using Windows.UI.ViewManagement; +#endif + +#if WINDOWS_UWP + namespace Xamarin.Forms.Platform.UWP #else + namespace Xamarin.Forms.Platform.WinRT #endif { - public abstract partial class Platform : IPlatform, INavigation, IToolbarProvider + public abstract class Platform : IPlatform, INavigation, IToolbarProvider { - internal static readonly BindableProperty RendererProperty = BindableProperty.CreateAttached("Renderer", - typeof(IVisualElementRenderer), typeof(Platform), default(IVisualElementRenderer)); + internal static readonly BindableProperty RendererProperty = BindableProperty.CreateAttached("Renderer", typeof(IVisualElementRenderer), typeof(Platform), default(IVisualElementRenderer)); + +#if WINDOWS_UWP + internal static StatusBar MobileStatusBar => ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar") ? StatusBar.GetForCurrentView() : null; +#endif public static IVisualElementRenderer GetRenderer(VisualElement element) { @@ -33,10 +50,9 @@ namespace Xamarin.Forms.Platform.WinRT public static IVisualElementRenderer CreateRenderer(VisualElement element) { if (element == null) - throw new ArgumentNullException(nameof(element)); + throw new ArgumentNullException("element"); - IVisualElementRenderer renderer = Registrar.Registered.GetHandler<IVisualElementRenderer>(element.GetType()) ?? - new DefaultRenderer(); + IVisualElementRenderer renderer = Registrar.Registered.GetHandler<IVisualElementRenderer>(element.GetType()) ?? new DefaultRenderer(); renderer.SetElement(element); return renderer; } @@ -44,14 +60,11 @@ namespace Xamarin.Forms.Platform.WinRT internal Platform(Windows.UI.Xaml.Controls.Page page) { if (page == null) - throw new ArgumentNullException(nameof(page)); + throw new ArgumentNullException("page"); _page = page; - _container = new Canvas - { - Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["RootContainerStyle"] - }; + _container = new Canvas { Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["RootContainerStyle"] }; _page.Content = _container; @@ -71,19 +84,38 @@ namespace Xamarin.Forms.Platform.WinRT UpdateBounds(); #if WINDOWS_UWP - InitializeStatusBar(); + StatusBar statusBar = MobileStatusBar; + if (statusBar != null) + { + statusBar.Showing += (sender, args) => UpdateBounds(); + statusBar.Hiding += (sender, args) => UpdateBounds(); + + // UWP 14393 Bug: If RequestedTheme is Light (which it is by default), then the + // status bar uses White Foreground with White Background. + // UWP 10586 Bug: If RequestedTheme is Light (which it is by default), then the + // status bar uses Black Foreground with Black Background. + // Since the Light theme should have a Black on White status bar, we will set it explicitly. + // This can be overriden by setting the status bar colors in App.xaml.cs OnLaunched. + + if (statusBar.BackgroundColor == null && statusBar.ForegroundColor == null && Windows.UI.Xaml.Application.Current.RequestedTheme == ApplicationTheme.Light) + { + statusBar.BackgroundColor = Colors.White; + statusBar.ForegroundColor = Colors.Black; + statusBar.BackgroundOpacity = 1; + } + } #endif } internal void SetPage(Page newRoot) { if (newRoot == null) - throw new ArgumentNullException(nameof(newRoot)); + throw new ArgumentNullException("newRoot"); _navModel.Clear(); _navModel.Push(newRoot, null); - SetCurrent(newRoot, true); + SetCurrent(newRoot, false, true); Application.Current.NavigationProxy.Inner = this; } @@ -124,8 +156,7 @@ namespace Xamarin.Forms.Platform.WinRT Task INavigation.PopToRootAsync(bool animated) { - throw new InvalidOperationException( - "PopToRootAsync is not supported globally on Windows, please use a NavigationPage."); + throw new InvalidOperationException("PopToRootAsync is not supported globally on Windows, please use a NavigationPage."); } void INavigation.RemovePage(Page page) @@ -135,8 +166,7 @@ namespace Xamarin.Forms.Platform.WinRT void INavigation.InsertPageBefore(Page page, Page before) { - throw new InvalidOperationException( - "InsertPageBefore is not supported globally on Windows, please use a NavigationPage."); + throw new InvalidOperationException("InsertPageBefore is not supported globally on Windows, please use a NavigationPage."); } Task INavigation.PushModalAsync(Page page) @@ -152,11 +182,11 @@ namespace Xamarin.Forms.Platform.WinRT Task INavigation.PushModalAsync(Page page, bool animated) { if (page == null) - throw new ArgumentNullException(nameof(page)); + throw new ArgumentNullException("page"); var tcs = new TaskCompletionSource<bool>(); _navModel.PushModal(page); - SetCurrent(page, completedCallback: () => tcs.SetResult(true)); + SetCurrent(page, animated, completedCallback: () => tcs.SetResult(true)); return tcs.Task; } @@ -164,7 +194,7 @@ namespace Xamarin.Forms.Platform.WinRT { var tcs = new TaskCompletionSource<Page>(); Page result = _navModel.PopModal(); - SetCurrent(_navModel.CurrentPage, true, () => tcs.SetResult(result)); + SetCurrent(_navModel.CurrentPage, animated, true, () => tcs.SetResult(result)); return tcs.Task; } @@ -205,6 +235,128 @@ namespace Xamarin.Forms.Platform.WinRT } } + internal IToolbarProvider GetToolbarProvider() + { + IToolbarProvider provider = null; + + Page element = _currentPage; + while (element != null) + { + provider = GetRenderer(element) as IToolbarProvider; + if (provider != null) + break; + + var pageContainer = element as IPageContainer<Page>; + element = pageContainer?.CurrentPage; + } + + if (provider != null && _toolbarProvider == null) + ClearCommandBar(); + + return provider; + } + + internal async Task UpdateToolbarItems() + { + CommandBar commandBar = await GetCommandBarAsync(); + if (commandBar != null) + { + commandBar.PrimaryCommands.Clear(); + commandBar.SecondaryCommands.Clear(); +#if WINDOWS_UWP + if (_page.BottomAppBar != null || _page.TopAppBar != null) + { + _page.BottomAppBar = null; + _page.TopAppBar = null; + _page.InvalidateMeasure(); + } +#endif + } + +#if !WINDOWS_UWP + commandBar = AddOpenMasterButton(commandBar); +#endif + +#if WINDOWS_UWP + var toolBarProvider = GetToolbarProvider() as IToolBarForegroundBinder; +#endif + + foreach (ToolbarItem item in _toolbarTracker.ToolbarItems.OrderBy(ti => ti.Priority)) + { + if (commandBar == null) + commandBar = CreateCommandBar(); + +#if WINDOWS_UWP + toolBarProvider?.BindForegroundColor(commandBar); +#endif + + var button = new AppBarButton(); + button.SetBinding(AppBarButton.LabelProperty, "Text"); + button.SetBinding(AppBarButton.IconProperty, "Icon", _fileImageSourcePathConverter); + button.Command = new MenuItemCommand(item); + button.DataContext = item; + + + ToolbarItemOrder order = item.Order == ToolbarItemOrder.Default ? ToolbarItemOrder.Primary : item.Order; + + if (order == ToolbarItemOrder.Primary) + { +#if WINDOWS_UWP + toolBarProvider?.BindForegroundColor(button); +#endif + commandBar.PrimaryCommands.Add(button); + } + else + commandBar.SecondaryCommands.Add(button); + } + + if (commandBar?.PrimaryCommands.Count + commandBar?.SecondaryCommands.Count == 0) + ClearCommandBar(); + } + +#if !WINDOWS_UWP + CommandBar AddOpenMasterButton(CommandBar commandBar) + { + if (!_toolbarTracker.HaveMasterDetail) + { + return commandBar; + } + + if (commandBar == null) + { + commandBar = CreateCommandBar(); + } + + Page target = _toolbarTracker.Target; + var mdp = target as MasterDetailPage; + while (mdp == null) + { + var container = target as IPageContainer<Page>; + if (container == null) + { + break; + } + + target = container.CurrentPage; + mdp = container.CurrentPage as MasterDetailPage; + } + + if (mdp == null || !mdp.ShouldShowToolbarButton()) + { + return commandBar; + } + + var openMaster = new AppBarButton { DataContext = mdp }; + openMaster.SetBinding(AppBarButton.LabelProperty, "Master.Title"); + openMaster.SetBinding(AppBarButton.IconProperty, "Master.Icon", _fileImageSourcePathConverter); + openMaster.Click += (s, a) => { mdp.IsPresented = !mdp.IsPresented; }; + + commandBar.PrimaryCommands.Add(openMaster); + + return commandBar; + } +#endif + Rectangle _bounds; readonly Canvas _container; readonly Windows.UI.Xaml.Controls.Page _page; @@ -214,17 +366,32 @@ namespace Xamarin.Forms.Platform.WinRT readonly ToolbarTracker _toolbarTracker = new ToolbarTracker(); readonly FileImageSourcePathConverter _fileImageSourcePathConverter = new FileImageSourcePathConverter(); +#pragma warning disable 649 + IToolbarProvider _toolbarProvider; +#pragma warning restore 649 + + class ToolbarProvider : IToolbarProvider + { + readonly Task<CommandBar> _commandBar; + + public ToolbarProvider(CommandBar commandBar) + { + _commandBar = Task.FromResult(commandBar); + } + + public CommandBar CommandBar => _commandBar.Result; + + public Task<CommandBar> GetCommandBarAsync() + { + return _commandBar; + } + } Windows.UI.Xaml.Controls.ProgressBar GetBusyIndicator() { if (_busyIndicator == null) { - _busyIndicator = new Windows.UI.Xaml.Controls.ProgressBar - { - IsIndeterminate = true, - Visibility = Visibility.Collapsed, - VerticalAlignment = VerticalAlignment.Top - }; + _busyIndicator = new Windows.UI.Xaml.Controls.ProgressBar { IsIndeterminate = true, Visibility = Visibility.Collapsed, VerticalAlignment = VerticalAlignment.Top }; Canvas.SetZIndex(_busyIndicator, 1); _container.Children.Add(_busyIndicator); @@ -250,7 +417,7 @@ namespace Xamarin.Forms.Platform.WinRT Page removed = _navModel.PopModal(); if (removed != null) { - SetCurrent(_navModel.CurrentPage, true); + SetCurrent(_navModel.CurrentPage, true, true); handled = true; } } @@ -269,13 +436,18 @@ namespace Xamarin.Forms.Platform.WinRT _currentActionSheet = null; } + void UpdateBounds() + { + _bounds = new Rectangle(0, 0, _container.ActualWidth, _container.ActualHeight); + } + void OnRendererSizeChanged(object sender, SizeChangedEventArgs sizeChangedEventArgs) { UpdateBounds(); UpdatePageSizes(); } - async void SetCurrent(Page newPage, bool popping = false, Action completedCallback = null) + async void SetCurrent(Page newPage, bool animated, bool popping = false, Action completedCallback = null) { if (newPage == _currentPage) return; @@ -300,22 +472,84 @@ namespace Xamarin.Forms.Platform.WinRT pageRenderer.ContainerElement.Width = _container.ActualWidth; pageRenderer.ContainerElement.Height = _container.ActualHeight; - completedCallback?.Invoke(); + if (completedCallback != null) + completedCallback(); _currentPage = newPage; UpdateToolbarTracker(); -#if WINDOWS_UWP UpdateToolbarTitle(newPage); -#endif await UpdateToolbarItems(); } + void UpdateToolbarTitle(Page page) + { + if (_toolbarProvider == null) + return; + + ((ToolbarProvider)_toolbarProvider).CommandBar.Content = page.Title; + } + Task<CommandBar> IToolbarProvider.GetCommandBarAsync() { return GetCommandBarAsync(); } +#pragma warning disable 1998 // considered for removal + async Task<CommandBar> GetCommandBarAsync() +#pragma warning restore 1998 + { +#if !WINDOWS_UWP + return _page.BottomAppBar as CommandBar; +#else + IToolbarProvider provider = GetToolbarProvider(); + //var titleProvider = provider as ITitleProvider; + if (provider == null) // || (titleProvider != null && !titleProvider.ShowTitle)) + return null; + + return await provider.GetCommandBarAsync(); +#endif + } + + CommandBar CreateCommandBar() + { +#if !WINDOWS_UWP + var commandBar = new CommandBar(); + _page.BottomAppBar = commandBar; + return commandBar; +#else + + var bar = new FormsCommandBar(); + if (Device.Idiom != TargetIdiom.Phone) + bar.Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["TitleToolbar"]; + + _toolbarProvider = new ToolbarProvider(bar); + + if (Device.Idiom == TargetIdiom.Phone) + _page.BottomAppBar = bar; + else + _page.TopAppBar = bar; + + return bar; +#endif + } + + void ClearCommandBar() + { +#if !WINDOWS_UWP + _page.BottomAppBar = null; +#else + if (_toolbarProvider != null) + { + _toolbarProvider = null; + if (Device.Idiom == TargetIdiom.Phone) + _page.BottomAppBar = null; + else + _page.TopAppBar = null; + } +#endif + } + async void OnToolbarItemsChanged(object sender, EventArgs e) { await UpdateToolbarItems(); @@ -331,6 +565,163 @@ namespace Xamarin.Forms.Platform.WinRT ActionSheetArguments _actionSheetOptions; Popup _currentActionSheet; +#if WINDOWS_UWP + async void OnPageActionSheet(Page sender, ActionSheetArguments options) + { + List<string> buttons = options.Buttons.ToList(); + + var list = new Windows.UI.Xaml.Controls.ListView + { + Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["ActionSheetList"], + ItemsSource = buttons, + IsItemClickEnabled = true + }; + + var dialog = new ContentDialog + { + Template = (Windows.UI.Xaml.Controls.ControlTemplate)Windows.UI.Xaml.Application.Current.Resources["MyContentDialogControlTemplate"], + Content = list, + Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["ActionSheetStyle"] + }; + + if (options.Title != null) + dialog.Title = options.Title; + + list.ItemClick += (s, e) => + { + dialog.Hide(); + options.SetResult((string)e.ClickedItem); + }; + + TypedEventHandler<CoreWindow, CharacterReceivedEventArgs> onEscapeButtonPressed = delegate(CoreWindow window, CharacterReceivedEventArgs args) + { + if (args.KeyCode == 27) + { + dialog.Hide(); + options.SetResult(ContentDialogResult.None.ToString()); + } + }; + + Window.Current.CoreWindow.CharacterReceived += onEscapeButtonPressed; + + _actionSheetOptions = options; + + if (options.Cancel != null) + dialog.SecondaryButtonText = options.Cancel; + + if (options.Destruction != null) + dialog.PrimaryButtonText = options.Destruction; + + ContentDialogResult result = await dialog.ShowAsync(); + if (result == ContentDialogResult.Secondary) + options.SetResult(options.Cancel); + else if (result == ContentDialogResult.Primary) + options.SetResult(options.Destruction); + + Window.Current.CoreWindow.CharacterReceived -= onEscapeButtonPressed; + } +#else + void OnPageActionSheet(Page sender, ActionSheetArguments options) + { + var finalArguments = new List<string>(); + if (options.Destruction != null) + finalArguments.Add(options.Destruction); + if (options.Buttons != null) + finalArguments.AddRange(options.Buttons); + if (options.Cancel != null) + finalArguments.Add(options.Cancel); + + var list = new Windows.UI.Xaml.Controls.ListView + { + Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["ActionSheetList"], + ItemsSource = finalArguments, + IsItemClickEnabled = true + }; + + list.ItemClick += (s, e) => + { + _currentActionSheet.IsOpen = false; + options.SetResult((string)e.ClickedItem); + }; + + _actionSheetOptions = options; + + Size size = Device.Info.ScaledScreenSize; + + var stack = new StackPanel + { + MinWidth = 100, + Children = + { + new TextBlock + { + Text = options.Title ?? string.Empty, + Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["TitleTextBlockStyle"], + Margin = new Windows.UI.Xaml.Thickness(0, 0, 0, 10), + Visibility = options.Title != null ? Visibility.Visible : Visibility.Collapsed + }, + list + } + }; + + var border = new Border + { + Child = stack, + BorderBrush = new SolidColorBrush(Colors.White), + BorderThickness = new Windows.UI.Xaml.Thickness(1), + Padding = new Windows.UI.Xaml.Thickness(15), + Background = (Brush)Windows.UI.Xaml.Application.Current.Resources["AppBarBackgroundThemeBrush"] + }; + + Windows.UI.Xaml.Controls.Grid.SetRow(border, 1); + Windows.UI.Xaml.Controls.Grid.SetColumn(border, 1); + + var container = new Windows.UI.Xaml.Controls.Grid + { + RowDefinitions = + { + new Windows.UI.Xaml.Controls.RowDefinition { Height = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Star) }, + new Windows.UI.Xaml.Controls.RowDefinition { Height = new Windows.UI.Xaml.GridLength(0, Windows.UI.Xaml.GridUnitType.Auto) }, + new Windows.UI.Xaml.Controls.RowDefinition { Height = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Star) } + }, + ColumnDefinitions = + { + new Windows.UI.Xaml.Controls.ColumnDefinition { Width = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Star) }, + new Windows.UI.Xaml.Controls.ColumnDefinition { Width = new Windows.UI.Xaml.GridLength(0, Windows.UI.Xaml.GridUnitType.Auto) }, + new Windows.UI.Xaml.Controls.ColumnDefinition { Width = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Star) } + }, + Height = size.Height, + Width = size.Width, + Children = { border } + }; + + var bgPopup = new Popup { Child = new Canvas { Width = size.Width, Height = size.Height, Background = new SolidColorBrush(new Windows.UI.Color { A = 128, R = 0, G = 0, B = 0 }) } }; + + bgPopup.IsOpen = true; + + _currentActionSheet = new Popup { ChildTransitions = new TransitionCollection { new PopupThemeTransition() }, IsLightDismissEnabled = true, Child = container }; + + _currentActionSheet.Closed += (s, e) => + { + bgPopup.IsOpen = false; + CancelActionSheet(); + }; + + if (Device.Idiom == TargetIdiom.Phone) + { + double height = _page.ActualHeight; + stack.Height = height; + stack.Width = size.Width; + border.BorderThickness = new Windows.UI.Xaml.Thickness(0); + + _currentActionSheet.Height = height; + _currentActionSheet.VerticalOffset = size.Height - height; + } + + _currentActionSheet.IsOpen = true; + } +#endif + async void OnPageAlert(Page sender, AlertArguments options) { string content = options.Message ?? options.Title ?? string.Empty; @@ -368,7 +759,7 @@ namespace Xamarin.Forms.Platform.WinRT } } } - + // refer to http://stackoverflow.com/questions/29209954/multiple-messagedialog-app-crash for why this is used // in order to allow for multiple MessageDialogs, or a crash occurs otherwise public static class MessageDialogExtensions @@ -382,8 +773,8 @@ namespace Xamarin.Forms.Platform.WinRT await _currentDialogShowRequest.Task; } - TaskCompletionSource<MessageDialog> request = _currentDialogShowRequest = new TaskCompletionSource<MessageDialog>(); - IUICommand result = await dialog.ShowAsync(); + var request = _currentDialogShowRequest = new TaskCompletionSource<MessageDialog>(); + var result = await dialog.ShowAsync(); _currentDialogShowRequest = null; request.SetResult(dialog); diff --git a/Xamarin.Forms.Platform.WinRT/PlatformWinRT.cs b/Xamarin.Forms.Platform.WinRT/PlatformWinRT.cs deleted file mode 100644 index 5e11c8d8..00000000 --- a/Xamarin.Forms.Platform.WinRT/PlatformWinRT.cs +++ /dev/null @@ -1,211 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Windows.UI; -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Controls.Primitives; -using Windows.UI.Xaml.Media; -using Windows.UI.Xaml.Media.Animation; - -namespace Xamarin.Forms.Platform.WinRT -{ - public abstract partial class Platform - { - CommandBar AddOpenMasterButton(CommandBar commandBar) - { - if (!_toolbarTracker.HaveMasterDetail) - { - return commandBar; - } - - if (commandBar == null) - { - commandBar = CreateCommandBar(); - } - - Page target = _toolbarTracker.Target; - var mdp = target as MasterDetailPage; - while (mdp == null) - { - var container = target as IPageContainer<Page>; - if (container == null) - { - break; - } - - target = container.CurrentPage; - mdp = container.CurrentPage as MasterDetailPage; - } - - if (mdp == null || !mdp.ShouldShowToolbarButton()) - { - return commandBar; - } - - var openMaster = new AppBarButton { DataContext = mdp }; - openMaster.SetBinding(AppBarButton.LabelProperty, "Master.Title"); - openMaster.SetBinding(AppBarButton.IconProperty, "Master.Icon", _fileImageSourcePathConverter); - openMaster.Click += (s, a) => { mdp.IsPresented = !mdp.IsPresented; }; - - commandBar.PrimaryCommands.Add(openMaster); - - return commandBar; - } - - CommandBar CreateCommandBar() - { - var commandBar = new CommandBar(); - _page.BottomAppBar = commandBar; - return commandBar; - } - - void UpdateBounds() - { - _bounds = new Rectangle(0, 0, _page.ActualWidth, _page.ActualHeight); - } - - Task<CommandBar> GetCommandBarAsync() - { - return Task.FromResult(_page.BottomAppBar as CommandBar); - } - - void ClearCommandBar() - { - _page.BottomAppBar = null; - } - - void OnPageActionSheet(Page sender, ActionSheetArguments options) - { - var finalArguments = new List<string>(); - if (options.Destruction != null) - finalArguments.Add(options.Destruction); - if (options.Buttons != null) - finalArguments.AddRange(options.Buttons); - if (options.Cancel != null) - finalArguments.Add(options.Cancel); - - var list = new Windows.UI.Xaml.Controls.ListView - { - Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["ActionSheetList"], - ItemsSource = finalArguments, - IsItemClickEnabled = true - }; - - list.ItemClick += (s, e) => - { - _currentActionSheet.IsOpen = false; - options.SetResult((string)e.ClickedItem); - }; - - _actionSheetOptions = options; - - Size size = Device.Info.ScaledScreenSize; - - var stack = new StackPanel - { - MinWidth = 100, - Children = - { - new TextBlock - { - Text = options.Title ?? string.Empty, - Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["TitleTextBlockStyle"], - Margin = new Windows.UI.Xaml.Thickness(0, 0, 0, 10), - Visibility = options.Title != null ? Visibility.Visible : Visibility.Collapsed - }, - list - } - }; - - var border = new Border - { - Child = stack, - BorderBrush = new SolidColorBrush(Colors.White), - BorderThickness = new Windows.UI.Xaml.Thickness(1), - Padding = new Windows.UI.Xaml.Thickness(15), - Background = (Brush)Windows.UI.Xaml.Application.Current.Resources["AppBarBackgroundThemeBrush"] - }; - - Windows.UI.Xaml.Controls.Grid.SetRow(border, 1); - Windows.UI.Xaml.Controls.Grid.SetColumn(border, 1); - - var container = new Windows.UI.Xaml.Controls.Grid - { - RowDefinitions = - { - new Windows.UI.Xaml.Controls.RowDefinition { Height = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Star) }, - new Windows.UI.Xaml.Controls.RowDefinition { Height = new Windows.UI.Xaml.GridLength(0, Windows.UI.Xaml.GridUnitType.Auto) }, - new Windows.UI.Xaml.Controls.RowDefinition { Height = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Star) } - }, - ColumnDefinitions = - { - new Windows.UI.Xaml.Controls.ColumnDefinition { Width = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Star) }, - new Windows.UI.Xaml.Controls.ColumnDefinition { Width = new Windows.UI.Xaml.GridLength(0, Windows.UI.Xaml.GridUnitType.Auto) }, - new Windows.UI.Xaml.Controls.ColumnDefinition { Width = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Star) } - }, - Height = size.Height, - Width = size.Width, - Children = { border } - }; - - var bgPopup = new Popup { Child = new Canvas { Width = size.Width, Height = size.Height, Background = new SolidColorBrush(new Windows.UI.Color { A = 128, R = 0, G = 0, B = 0 }) } }; - - bgPopup.IsOpen = true; - - _currentActionSheet = new Popup { ChildTransitions = new TransitionCollection { new PopupThemeTransition() }, IsLightDismissEnabled = true, Child = container }; - - _currentActionSheet.Closed += (s, e) => - { - bgPopup.IsOpen = false; - CancelActionSheet(); - }; - - if (Device.Idiom == TargetIdiom.Phone) - { - double height = _page.ActualHeight; - stack.Height = height; - stack.Width = size.Width; - border.BorderThickness = new Windows.UI.Xaml.Thickness(0); - - _currentActionSheet.Height = height; - _currentActionSheet.VerticalOffset = size.Height - height; - } - - _currentActionSheet.IsOpen = true; - } - - internal async Task UpdateToolbarItems() - { - CommandBar commandBar = await GetCommandBarAsync(); - if (commandBar != null) - { - commandBar.PrimaryCommands.Clear(); - commandBar.SecondaryCommands.Clear(); - } - - commandBar = AddOpenMasterButton(commandBar); - - foreach (ToolbarItem item in _toolbarTracker.ToolbarItems.OrderBy(ti => ti.Priority)) - { - if (commandBar == null) - commandBar = CreateCommandBar(); - - var button = new AppBarButton(); - button.SetBinding(AppBarButton.LabelProperty, "Text"); - button.SetBinding(AppBarButton.IconProperty, "Icon", _fileImageSourcePathConverter); - button.Command = new MenuItemCommand(item); - button.DataContext = item; - - ToolbarItemOrder order = item.Order == ToolbarItemOrder.Default ? ToolbarItemOrder.Primary : item.Order; - if (order == ToolbarItemOrder.Primary) - commandBar.PrimaryCommands.Add(button); - else - commandBar.SecondaryCommands.Add(button); - } - - if (commandBar?.PrimaryCommands.Count + commandBar?.SecondaryCommands.Count == 0) - ClearCommandBar(); - } - } -} diff --git a/Xamarin.Forms.Platform.WinRT/SliderRenderer.cs b/Xamarin.Forms.Platform.WinRT/SliderRenderer.cs index 0fff1496..cf188f15 100644 --- a/Xamarin.Forms.Platform.WinRT/SliderRenderer.cs +++ b/Xamarin.Forms.Platform.WinRT/SliderRenderer.cs @@ -24,11 +24,7 @@ namespace Xamarin.Forms.Platform.WinRT var slider = new Windows.UI.Xaml.Controls.Slider(); SetNativeControl(slider); - Control.Minimum = e.NewElement.Minimum; - Control.Maximum = e.NewElement.Maximum; - Control.Value = e.NewElement.Value; - - slider.ValueChanged += OnNativeValueChanged; + slider.ValueChanged += OnNativeValueCHanged; // Even when using Center/CenterAndExpand, a Slider has an oddity where it looks // off-center in its layout by a smidge. The default templates are slightly different @@ -53,6 +49,10 @@ namespace Xamarin.Forms.Platform.WinRT double stepping = Math.Min((e.NewElement.Maximum - e.NewElement.Minimum) / 10, 1); Control.StepFrequency = stepping; Control.SmallChange = stepping; + + Control.Minimum = e.NewElement.Minimum; + Control.Maximum = e.NewElement.Maximum; + Control.Value = e.NewElement.Value; } } @@ -71,7 +71,7 @@ namespace Xamarin.Forms.Platform.WinRT } } - void OnNativeValueChanged(object sender, RangeBaseValueChangedEventArgs e) + void OnNativeValueCHanged(object sender, RangeBaseValueChangedEventArgs e) { ((IElementController)Element).SetValueFromRenderer(Slider.ValueProperty, e.NewValue); } diff --git a/Xamarin.Forms.Platform.WinRT/ViewRenderer.cs b/Xamarin.Forms.Platform.WinRT/ViewRenderer.cs index 0017531f..148da1b3 100644 --- a/Xamarin.Forms.Platform.WinRT/ViewRenderer.cs +++ b/Xamarin.Forms.Platform.WinRT/ViewRenderer.cs @@ -1,6 +1,5 @@ using Windows.UI.Xaml; using Windows.UI.Xaml.Automation; -using Windows.UI.Xaml.Automation.Peers; #if WINDOWS_UWP @@ -12,11 +11,6 @@ namespace Xamarin.Forms.Platform.WinRT { public class ViewRenderer<TElement, TNativeElement> : VisualElementRenderer<TElement, TNativeElement> where TElement : View where TNativeElement : FrameworkElement { - string _defaultAutomationPropertiesName; - AccessibilityView? _defaultAutomationPropertiesAccessibilityView; - string _defaultAutomationPropertiesHelpText; - UIElement _defaultAutomationPropertiesLabeledBy; - protected override void OnElementChanged(ElementChangedEventArgs<TElement> e) { base.OnElementChanged(e); @@ -39,97 +33,5 @@ namespace Xamarin.Forms.Platform.WinRT Control.SetValue(AutomationProperties.AutomationIdProperty, id); } } - protected override void SetAutomationPropertiesName() - { - if (Control == null) - { - base.SetAutomationPropertiesName(); - return; - } - - if (Element == null) - return; - - if (_defaultAutomationPropertiesName == null) - _defaultAutomationPropertiesName = (string)Control.GetValue(AutomationProperties.NameProperty); - - var elemValue = (string)Element.GetValue(Accessibility.NameProperty); - - if (!string.IsNullOrWhiteSpace(elemValue)) - Control.SetValue(AutomationProperties.NameProperty, elemValue); - else - Control.SetValue(AutomationProperties.NameProperty, _defaultAutomationPropertiesName); - } - - protected override void SetAutomationPropertiesAccessibilityView() - { - if (Control == null) - { - base.SetAutomationPropertiesAccessibilityView(); - return; - } - - if (Element == null) - return; - - if (!_defaultAutomationPropertiesAccessibilityView.HasValue) - _defaultAutomationPropertiesAccessibilityView = (AccessibilityView)Control.GetValue(AutomationProperties.AccessibilityViewProperty); - - var newValue = _defaultAutomationPropertiesAccessibilityView; - var elemValue = (bool?)Element.GetValue(Accessibility.IsInAccessibleTreeProperty); - - if (elemValue == true) - newValue = AccessibilityView.Content; - else if (elemValue == false) - newValue = AccessibilityView.Raw; - - Control.SetValue(AutomationProperties.AccessibilityViewProperty, newValue); - } - - protected override void SetAutomationPropertiesHelpText() - { - if (Control == null) - { - base.SetAutomationPropertiesHelpText(); - return; - } - - if (Element == null) - return; - - if (_defaultAutomationPropertiesHelpText == null) - _defaultAutomationPropertiesHelpText = (string)Control.GetValue(AutomationProperties.HelpTextProperty); - - var elemValue = (string)Element.GetValue(Accessibility.HintProperty); - - if (!string.IsNullOrWhiteSpace(elemValue)) - Control.SetValue(AutomationProperties.HelpTextProperty, elemValue); - else - Control.SetValue(AutomationProperties.HelpTextProperty, _defaultAutomationPropertiesHelpText); - } - - protected override void SetAutomationPropertiesLabeledBy() - { - if (Control == null) - { - base.SetAutomationPropertiesLabeledBy(); - return; - } - - if (Element == null) - return; - - if (_defaultAutomationPropertiesLabeledBy == null) - _defaultAutomationPropertiesLabeledBy = (UIElement)Control.GetValue(AutomationProperties.LabeledByProperty); - - var elemValue = (VisualElement)Element.GetValue(Accessibility.LabeledByProperty); - var renderer = elemValue?.GetOrCreateRenderer(); - var nativeElement = renderer?.GetNativeElement(); - - if (nativeElement != null) - Control.SetValue(AutomationProperties.LabeledByProperty, nativeElement); - else - Control.SetValue(AutomationProperties.LabeledByProperty, _defaultAutomationPropertiesLabeledBy); - } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.WinRT/VisualElementRenderer.cs b/Xamarin.Forms.Platform.WinRT/VisualElementRenderer.cs index 402d1da8..b81f73e3 100644 --- a/Xamarin.Forms.Platform.WinRT/VisualElementRenderer.cs +++ b/Xamarin.Forms.Platform.WinRT/VisualElementRenderer.cs @@ -4,7 +4,6 @@ using System.ComponentModel; using Windows.Foundation; using Windows.UI.Xaml; using Windows.UI.Xaml.Automation; -using Windows.UI.Xaml.Automation.Peers; using Windows.UI.Xaml.Controls; #if WINDOWS_UWP @@ -18,10 +17,6 @@ namespace Xamarin.Forms.Platform.WinRT public class VisualElementRenderer<TElement, TNativeElement> : Panel, IVisualElementRenderer, IDisposable, IEffectControlProvider where TElement : VisualElement where TNativeElement : FrameworkElement { - string _defaultAutomationPropertiesName; - AccessibilityView? _defaultAutomationPropertiesAccessibilityView; - string _defaultAutomationPropertiesHelpText; - UIElement _defaultAutomationPropertiesLabeledBy; bool _disposed; EventHandler<VisualElementChangedEventArgs> _elementChangedHandlers; VisualElementTracker<TElement, TNativeElement> _tracker; @@ -113,11 +108,6 @@ namespace Xamarin.Forms.Platform.WinRT return new SizeRequest(result); } - public UIElement GetNativeElement() - { - return Control; - } - public void SetElement(VisualElement element) { TElement oldElement = Element; @@ -297,14 +287,6 @@ namespace Xamarin.Forms.Platform.WinRT UpdateEnabled(); else if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName) UpdateBackgroundColor(); - else if (e.PropertyName == Accessibility.HintProperty.PropertyName) - SetAutomationPropertiesHelpText(); - else if (e.PropertyName == Accessibility.NameProperty.PropertyName) - SetAutomationPropertiesName(); - else if (e.PropertyName == Accessibility.IsInAccessibleTreeProperty.PropertyName) - SetAutomationPropertiesAccessibilityView(); - else if (e.PropertyName == Accessibility.LabeledByProperty.PropertyName) - SetAutomationPropertiesLabeledBy(); } protected virtual void OnRegisterEffect(PlatformEffect effect) @@ -318,75 +300,6 @@ namespace Xamarin.Forms.Platform.WinRT SetValue(AutomationProperties.AutomationIdProperty, id); } - protected virtual void SetAutomationPropertiesName() - { - if (Element == null || Control == null) - return; - - if (_defaultAutomationPropertiesName == null) - _defaultAutomationPropertiesName = (string)Control.GetValue(AutomationProperties.NameProperty); - - var elemValue = (string)Element.GetValue(Accessibility.NameProperty); - - if (!string.IsNullOrWhiteSpace(elemValue)) - Control.SetValue(AutomationProperties.NameProperty, elemValue); - else - Control.SetValue(AutomationProperties.NameProperty, _defaultAutomationPropertiesName); - } - - protected virtual void SetAutomationPropertiesAccessibilityView() - { - if (Element == null || Control == null) - return; - - if (!_defaultAutomationPropertiesAccessibilityView.HasValue) - _defaultAutomationPropertiesAccessibilityView = (AccessibilityView)Control.GetValue(AutomationProperties.AccessibilityViewProperty); - - var newValue = _defaultAutomationPropertiesAccessibilityView; - var elemValue = (bool?)Element.GetValue(Accessibility.IsInAccessibleTreeProperty); - - if (elemValue == true) - newValue = AccessibilityView.Content; - else if (elemValue == false) - newValue = AccessibilityView.Raw; - - Control.SetValue(AutomationProperties.AccessibilityViewProperty, newValue); - } - - protected virtual void SetAutomationPropertiesHelpText() - { - if (Element == null || Control == null) - return; - - if (_defaultAutomationPropertiesHelpText == null) - _defaultAutomationPropertiesHelpText = (string)Control.GetValue(AutomationProperties.HelpTextProperty); - - var elemValue = (string)Element.GetValue(Accessibility.HintProperty); - - if (!string.IsNullOrWhiteSpace(elemValue)) - Control.SetValue(AutomationProperties.HelpTextProperty, elemValue); - else - Control.SetValue(AutomationProperties.HelpTextProperty, _defaultAutomationPropertiesHelpText); - } - - protected virtual void SetAutomationPropertiesLabeledBy() - { - if (Element == null || Control == null) - return; - - if (_defaultAutomationPropertiesLabeledBy == null) - _defaultAutomationPropertiesLabeledBy = (UIElement)Control.GetValue(AutomationProperties.LabeledByProperty); - - var elemValue = (VisualElement)Element.GetValue(Accessibility.LabeledByProperty); - var renderer = elemValue?.GetOrCreateRenderer(); - var nativeElement = renderer?.GetNativeElement(); - - if (nativeElement != null) - Control.SetValue(AutomationProperties.LabeledByProperty, nativeElement); - else - Control.SetValue(AutomationProperties.LabeledByProperty, _defaultAutomationPropertiesLabeledBy); - } - protected void SetNativeControl(TNativeElement control) { TNativeElement oldControl = Control; @@ -454,10 +367,6 @@ namespace Xamarin.Forms.Platform.WinRT protected virtual void UpdateNativeControl() { UpdateEnabled(); - SetAutomationPropertiesHelpText(); - SetAutomationPropertiesName(); - SetAutomationPropertiesAccessibilityView(); - SetAutomationPropertiesLabeledBy(); } internal virtual void OnElementFocusChangeRequested(object sender, VisualElement.FocusRequestArgs args) diff --git a/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj b/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj index 766fd728..22068d0b 100644 --- a/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj +++ b/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj @@ -68,8 +68,6 @@ </Compile> </ItemGroup> <ItemGroup Condition=" '$(OS)' != 'Unix' "> - <Compile Include="NavigationPageRendererWinRT.cs" /> - <Compile Include="PlatformWinRT.cs" /> <Compile Include="BrushHelpers.cs" /> <Compile Include="NativeBindingExtensions.cs" /> <Compile Include="NativeEventWrapper.cs" /> @@ -194,4 +192,4 @@ <Target Name="AfterBuild"> </Target> --> -</Project>
\ No newline at end of file +</Project> |