public static UIElement ConvertPageToUIElement(this Page page, WpfApplicationPage applicationPage) { var application = new DefaultApplication(); application.MainPage = page; var result = new Platform(applicationPage); result.SetPage(page); return(result.GetCanvas()); }
internal Platform(WpfApplicationPage page) { _tracker.SeparateMasterDetail = true; page.BackKeyPress += OnBackKeyPress; _page = page; _renderer = new Canvas(); _renderer.SizeChanged += RendererSizeChanged; _renderer.Loaded += (sender, args) => UpdateSystemTray(); _tracker.CollectionChanged += (sender, args) => UpdateToolbarItems(); ProgressIndicator indicator; SystemTray.SetProgressIndicator(page, indicator = new ProgressIndicator { IsVisible = false, IsIndeterminate = true }); var busyCount = 0; MessagingCenter.Subscribe(this, Page.BusySetSignalName, (Page sender, bool enabled) => { busyCount = Math.Max(0, enabled ? busyCount + 1 : busyCount - 1); indicator.IsVisible = busyCount > 0; }); MessagingCenter.Subscribe(this, Page.AlertSignalName, (Page sender, AlertArguments arguments) => { var messageBox = new CustomMessageBox { Title = arguments.Title, Message = arguments.Message }; if (arguments.Accept != null) { messageBox.LeftButtonContent = arguments.Accept; } messageBox.RightButtonContent = arguments.Cancel; messageBox.Show(); _visibleMessageBox = messageBox; messageBox.Dismissed += (o, args) => { arguments.SetResult(args.Result == CustomMessageBoxResult.LeftButton); _visibleMessageBox = null; }; }); MessagingCenter.Subscribe(this, Page.ActionSheetSignalName, (Page sender, ActionSheetArguments arguments) => { var messageBox = new CustomMessageBox { Title = arguments.Title }; var listBox = new ListBox { FontSize = 36, Margin = new System.Windows.Thickness(12) }; var itemSource = new List <string>(); if (!string.IsNullOrWhiteSpace(arguments.Destruction)) { itemSource.Add(arguments.Destruction); } itemSource.AddRange(arguments.Buttons); if (!string.IsNullOrWhiteSpace(arguments.Cancel)) { itemSource.Add(arguments.Cancel); } listBox.ItemsSource = itemSource.Select(s => new TextBlock { Text = s, Margin = new System.Windows.Thickness(0, 12, 0, 12) }); messageBox.Content = listBox; listBox.SelectionChanged += (o, args) => messageBox.Dismiss(); messageBox.Dismissed += (o, args) => { string result = listBox.SelectedItem != null ? ((TextBlock)listBox.SelectedItem).Text : null; arguments.SetResult(result); _visibleMessageBox = null; }; messageBox.Show(); _visibleMessageBox = messageBox; }); }