Exemplo n.º 1
0
        public ShellPage()
        {
            this.InitializeComponent();
            this.DataContext = this.ViewModel;


            if (ApiInformation.IsEventPresent("Windows.UI.Xaml.UIElement", nameof(this.PreviewKeyDown)))
            {
                this.PreviewKeyDown += this.Page_PreviewKeyDown;
            }

            MediaplayerViewmodel.Init(this.TransportControls);
            IList <KeyboardAccelerator> keyboardAccelerators;

            if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.UIElement", nameof(this.KeyboardAccelerators)))
            {
                keyboardAccelerators = this.KeyboardAccelerators;
            }
            else
            {
                keyboardAccelerators = new List <KeyboardAccelerator>();
            }
            this.ViewModel.Initialize(this.shellFrame, null, keyboardAccelerators);

            this.Loaded += this.ShellPage_Loaded;
        }
Exemplo n.º 2
0
        protected override void InitializeInternal()
        {
            base.InitializeInternal();

            if (Frame != null)
            {
                var service = CreateNavigationService(Frame);
                if (service != null)
                {
                    IocContainer.BindToConstant(service);
                }
            }

            var rootPresenter = GetRootPresenter();

            if (rootPresenter != null)
            {
                IocContainer.Get <IViewModelPresenter>().DynamicPresenters.Add(rootPresenter);
            }

            var application = Application.Current;

            if (application != null)
            {
                if (ApiInformation.IsEventPresent("Windows.UI.Xaml.Application", nameof(Application.EnteredBackground)))
                {
                    application.EnteredBackground += OnEnteredBackground;
                }
                if (ApiInformation.IsEventPresent("Windows.UI.Xaml.Application", nameof(Application.LeavingBackground)))
                {
                    application.LeavingBackground += OnLeavingBackground;
                }
            }
        }
        static DeviceInformationHelper()
        {
            CanReadScreenSize =
                ApiInformation.IsPropertyPresent(typeof(DisplayInformation).FullName, "ScreenHeightInRawPixels") &&
                ApiInformation.IsPropertyPresent(typeof(DisplayInformation).FullName, "ScreenWidthInRawPixels");

            // This must all be done from the leaving background event because DisplayInformation can only be used
            // from the main thread
            if (CanReadScreenSize &&
                ApiInformation.IsEventPresent(typeof(CoreApplication).FullName, "LeavingBackground"))
            {
                CoreApplication.LeavingBackground += (sender, e) =>
                {
                    lock (LockObject)
                    {
                        if (_didSetUpScreenSizeEvent)
                        {
                            return;
                        }
                        DisplayInformation.GetForCurrentView().OrientationChanged += (displayInfo, obj) =>
                        {
                            RefreshDisplayCache();
                        };
                        _didSetUpScreenSizeEvent = true;
                        RefreshDisplayCache();
                        DisplayInformationEventSemaphore.Release();
                    }
                };
            }
        }
Exemplo n.º 4
0
        public ApplicationLifecycleHelper()
        {
            // If the "LeavingBackground" event is present, use that for Resuming. Else, use CoreApplication.Resuming.
            if (ApiInformation.IsEventPresent(typeof(CoreApplication).FullName, "LeavingBackground"))
            {
                CoreApplication.LeavingBackground += InvokeResuming;

                // If the application has anything visible, then it has already started,
                // so invoke the resuming event immediately.
                InvokeResuming(null, EventArgs.Empty);
            }
            else
            {
                InvokeResuming(null, EventArgs.Empty);
            }

            // Subscribe to unhandled errors events.
            CoreApplication.UnhandledErrorDetected += (sender, eventArgs) =>
            {
                try
                {
                    // Intentionally propagate exception to get the exception object that crashed the app.
                    eventArgs.UnhandledError.Propagate();
                }
                catch (Exception exception)
                {
                    InvokeUnhandledExceptionOccurred(sender, exception);

                    // Since UnhandledError.Propagate marks the error as Handled, rethrow in order to only Log and not Handle.
                    // Use ExceptionDispatchInfo to avoid changing the stack-trace.
                    ExceptionDispatchInfo.Capture(exception).Throw();
                }
            };
        }
 public CustomVirtualStackPanel() {
     if (ApiInformation.IsEventPresent("Windows.UI.Xaml.FrameworkElement", "EffectiveViewportChanged")) {
         EffectiveViewportChanged += CustomVirtualStackPanel_EffectiveViewportChanged;
     } else {
         LayoutUpdated += CustomVirtualStackPanel_LayoutUpdated;
     }
 }
        /// <summary>
        /// Initiate Enumeration with specific RemoteSystemKind with Filters
        /// </summary>
        private async void GenerateSystemsWithFilterAsync(List <IRemoteSystemFilter> filter)
        {
            var accessStatus = await RemoteSystem.RequestAccessAsync();

            if (accessStatus == RemoteSystemAccessStatus.Allowed)
            {
                _remoteSystemWatcher = filter != null?RemoteSystem.CreateWatcher(filter) : RemoteSystem.CreateWatcher();

                _remoteSystemWatcher.RemoteSystemAdded   += RemoteSystemWatcher_RemoteSystemAdded;
                _remoteSystemWatcher.RemoteSystemRemoved += RemoteSystemWatcher_RemoteSystemRemoved;
                _remoteSystemWatcher.RemoteSystemUpdated += RemoteSystemWatcher_RemoteSystemUpdated;
                if (ApiInformation.IsEventPresent("Windows.System.RemoteSystems.RemoteSystemWatcher", "EnumerationCompleted"))
                {
                    _remoteSystemWatcher.EnumerationCompleted += RemoteSystemWatcher_EnumerationCompleted;
                }
                else
                {
                    ThreadPoolTimer.CreateTimer(
                        (e) =>
                    {
                        RemoteSystemWatcher_EnumerationCompleted(_remoteSystemWatcher, null);
                    }, TimeSpan.FromSeconds(2));
                }

                _remoteSystemWatcher.Start();
            }
        }
Exemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        public DeviceGestureService()
        {
            IsHardwareBackButtonPresent   = ApiInformation.IsEventPresent("Windows.Phone.UI.Input.HardwareButtons", "BackPressed");
            IsHardwareCameraButtonPresent = ApiInformation.IsEventPresent("Windows.Phone.UI.Input.HardwareButtons", "CameraPressed");

            IsKeyboardPresent = new KeyboardCapabilities().KeyboardPresent != 0;
            IsMousePresent    = new MouseCapabilities().MousePresent != 0;
            IsTouchPresent    = new TouchCapabilities().TouchPresent != 0;

            if (IsHardwareBackButtonPresent)
            {
                HardwareButtons.BackPressed += OnHardwareButtonsBackPressed;
            }

            if (IsHardwareCameraButtonPresent)
            {
                HardwareButtons.CameraHalfPressed += OnHardwareButtonCameraHalfPressed;
                HardwareButtons.CameraPressed     += OnHardwareButtonCameraPressed;
                HardwareButtons.CameraReleased    += OnHardwareButtonCameraReleased;
            }

            if (IsMousePresent)
            {
                MouseDevice.GetForCurrentView().MouseMoved += OnMouseMoved;
            }

            SystemNavigationManager.GetForCurrentView().BackRequested += OnSystemNavigationManagerBackRequested;

            Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated += OnAcceleratorKeyActivated;

            Window.Current.CoreWindow.PointerPressed += OnPointerPressed;
        }
Exemplo n.º 8
0
        public SnapPage()
        {
            InitializeComponent();

            // Adaptive Code: Ask explicitly for special hardware button events (back and camera buttons).
            _isBackButtonPresent   = ApiInformation.IsEventPresent("Windows.Phone.UI.Input.HardwareButtons", "BackPressed");
            _isCameraButtonPresent = ApiInformation.IsEventPresent("Windows.Phone.UI.Input.HardwareButtons", "CameraPressed");
        }
Exemplo n.º 9
0
 private void ItemsPanel_Loaded(object sender, RoutedEventArgs e)
 {
     if (ApiInformation.IsEventPresent("Windows.UI.Xaml.UIElement", nameof(this.PreviewKeyDown)))
     {
         var panel = sender as UIElement;
         panel.BringIntoViewRequested += this.ItemsWrapGrid_BringIntoViewRequested;
     }
 }
Exemplo n.º 10
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     Parameters = e.Parameter as StartGameParameters ?? new StartGameParameters( );
     if (ApiInformation.IsEventPresent(typeof(HardwareButtons).FullName,
                                       nameof(HardwareButtons.BackPressed)))
     {
         HardwareButtons.BackPressed += MainPageButton_Click;
     }
 }
Exemplo n.º 11
0
 public override void AddControl( )
 {
     if (ApiInformation.IsEventPresent("Windows.Phone.UI.Input.HardwareButtons",
                                       nameof(HardwareButtons.BackPressed)))
     {
         HardwareButtons.BackPressed += SettingPageButton_Click;
     }
     SettingPageButton.Click += SettingPageButton_Click;
 }
Exemplo n.º 12
0
        public PicturesPage()
        {
            InitializeComponent();

            DataContext = _viewModel;

            // Adaptive Code: Ask explicitly for special hardware button event (camera button).
            _isCameraButtonPresent = ApiInformation.IsEventPresent("Windows.Phone.UI.Input.HardwareButtons", "CameraPressed");
        }
Exemplo n.º 13
0
        /// <summary>
        ///
        /// </summary>
        public DeviceGestureService()
        {
            IsHardwareBackButtonPresent   = ApiInformation.IsEventPresent("Windows.Phone.UI.Input.HardwareButtons", "BackPressed");
            IsHardwareCameraButtonPresent = ApiInformation.IsEventPresent("Windows.Phone.UI.Input.HardwareButtons", "CameraPressed");

            IsKeyboardPresent = new KeyboardCapabilities().KeyboardPresent != 0;
            IsMousePresent    = new MouseCapabilities().MousePresent != 0;
            IsTouchPresent    = new TouchCapabilities().TouchPresent != 0;
        }
Exemplo n.º 14
0
        private void OnUnloaded(object sender, RoutedEventArgs e)
        {
            if (ApiInformation.IsEventPresent("Windows.ApplicationModel.DataTransfer.DataTransferManager", "ShareProvidersRequested") && !ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5))
            {
                DataTransferManager.GetForCurrentView().ShareProvidersRequested -= OnShareProvidersRequested;
            }

            DataTransferManager.GetForCurrentView().DataRequested -= OnDataRequested;

            List.SelectedItems.Clear();
        }
Exemplo n.º 15
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            if (ApiInformation.IsEventPresent("Windows.ApplicationModel.DataTransfer.DataTransferManager", "ShareProvidersRequested"))
            {
                DataTransferManager.GetForCurrentView().ShareProvidersRequested -= OnShareProvidersRequested;
                DataTransferManager.GetForCurrentView().ShareProvidersRequested += OnShareProvidersRequested;
            }

            DataTransferManager.GetForCurrentView().DataRequested -= OnDataRequested;
            DataTransferManager.GetForCurrentView().DataRequested += OnDataRequested;
        }
Exemplo n.º 16
0
 public override void AddControl( )
 {
     if (ApiInformation.IsEventPresent(typeof(HardwareButtons).FullName,
                                       nameof(HardwareButtons.BackPressed)))
     {
         HardwareButtons.BackPressed += MainPageButton_Click;
     }
     MainPageButton.Click       += MainPageButton_Click;
     AboutPageButton.Click      += AboutPageButton_Click;
     ThrowExceptionButton.Click += ThrowExceptionButton_Click;
 }
Exemplo n.º 17
0
 /// <summary>
 ///     Initializes the singleton application object.  This is the first line of authored code
 ///     executed, and as such is the logical equivalent of main() or WinMain().
 /// </summary>
 protected MvvmUwpApplicationBase()
 {
     Suspending += OnSuspending;
     if (ApiInformation.IsEventPresent("Windows.UI.Xaml.Application", "EnteredBackground"))
     {
         EnteredBackground += OnEnteredBackground;
     }
     if (ApiInformation.IsEventPresent("Windows.UI.Xaml.Application", "LeavingBackground"))
     {
         LeavingBackground += OnLeavingBackground;
     }
 }
Exemplo n.º 18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RadNumericBox" /> class.
        /// </summary>
        public RadNumericBox()
        {
            this.DefaultStyleKey = typeof(RadNumericBox);

            this.isPreviewKeyDownPresent = ApiInformation.IsEventPresent("Windows.UI.Xaml.UIElement", "PreviewKeyDown");
            if (!this.isPreviewKeyDownPresent)
            {
                this.textBoxKeyDownHandler = new KeyEventHandler(this.OnTextBoxPreviewKeyDown);
            }

            this.allowNullValueCache = true;
        }
Exemplo n.º 19
0
        public NowPlaying()
        {
            this.InitializeComponent();
            _            = this.InitAsync();
            this.Loaded += this.NowPlaying_Loaded;

            this.supportIntensety = Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.Composition.IAmbientLight2");

            if (ApiInformation.IsEventPresent("Windows.UI.Xaml.UIElement", nameof(this.PreviewKeyDown)))
            {
                this.PreviewKeyDown += this.NowPlaying_PreviewKeyDown;
            }
        }
Exemplo n.º 20
0
        public ChatSearchBar()
        {
            InitializeComponent();

            if (ApiInformation.IsEventPresent("Windows.UI.Xaml.UIElement", "PreviewKeyDown"))
            {
                Field.PreviewKeyDown += OnKeyDown;
            }
            else
            {
                Field.KeyDown += OnKeyDown;
            }
        }
Exemplo n.º 21
0
        public void Initialize()
        {
#if WINDOWS_UWP
            if (ApiInformation.IsEventPresent("Windows.UI.Xaml.Application", "EnteredBackground"))
            {
                Application.Current.EnteredBackground += OnEnteredBackground;
            }
            if (ApiInformation.IsEventPresent("Windows.UI.Xaml.Application", "LeavingBackground"))
            {
                Application.Current.LeavingBackground += OnLeavingBackground;
            }
#endif
        }
 public static void ExecuteIfEventPresent(string typeName, string eventName, Action action)
 {
     if (ApiInformation.IsEventPresent(typeName, eventName))
     {
         try
         {
             action();
         }
         catch (MissingMethodException)
         {
         }
     }
 }
Exemplo n.º 23
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            Bindings.Update();

            if (ApiInformation.IsEventPresent("Windows.ApplicationModel.DataTransfer.DataTransferManager", "ShareProvidersRequested") && !ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5))
            {
                DataTransferManager.GetForCurrentView().ShareProvidersRequested -= OnShareProvidersRequested;
                DataTransferManager.GetForCurrentView().ShareProvidersRequested += OnShareProvidersRequested;
            }

            DataTransferManager.GetForCurrentView().DataRequested -= OnDataRequested;
            DataTransferManager.GetForCurrentView().DataRequested += OnDataRequested;
        }
Exemplo n.º 24
0
        public ApplicationLifecycleHelper()
        {
            // Subscribe to Resuming and Suspending events.
            CoreApplication.Suspending += InvokeSuspended;

            // If the "LeavingBackground" event is present, use that for Resuming. Else, use CoreApplication.Resuming.
            if (ApiInformation.IsEventPresent(typeof(CoreApplication).FullName, "LeavingBackground"))
            {
                CoreApplication.LeavingBackground += InvokeResuming;

                // If the application has anything visible, then it has already started,
                // so invoke the resuming event immediately.
                HasStartedAndNeedsResume().ContinueWith(completedTask =>
                {
                    if (completedTask.Result)
                    {
                        InvokeResuming(null, EventArgs.Empty);
                    }
                });
            }
            else
            {
                // In versions of Windows 10 where the LeavingBackground event is unavailable, we consider this point to be
                // the start so invoke resuming (and subscribe to future resume events). If InvokeResuming were not called here,
                // the resuming event wouldn't be invoked until the *next* time the application is resumed, which is a problem
                // if the application is not currently suspended. The side effect is that regardless of whether UI is available
                // ever in the process, InvokeResuming will be called at least once (in the case where LeavingBackground isn't
                // available).
                CoreApplication.Resuming += InvokeResuming;
                InvokeResuming(null, EventArgs.Empty);
            }

            // Subscribe to unhandled errors events.
            CoreApplication.UnhandledErrorDetected += (sender, eventArgs) =>
            {
                try
                {
                    // Intentionally propagate exception to get the exception object that crashed the app.
                    eventArgs.UnhandledError.Propagate();
                }
                catch (Exception exception)
                {
                    InvokeUnhandledExceptionOccurred(sender, exception);

                    // Since UnhandledError.Propagate marks the error as Handled, rethrow in order to only Log and not Handle.
                    // Use ExceptionDispatchInfo to avoid changing the stack-trace.
                    ExceptionDispatchInfo.Capture(exception).Throw();
                }
            };
        }
Exemplo n.º 25
0
 protected override void OnDetaching()
 {
     base.OnDetaching();
     if (ApiInformation.IsEventPresent(typeof(UIElement).FullName, nameof(UIElement.PreviewKeyDown)))
     {
         this.AssociatedObject.PreviewKeyDown -= this.AssociatedObject_PreviewKeyDown;
     }
     if (ApiInformation.IsEventPresent(typeof(TextBox).FullName, nameof(TextBox.Paste)))
     {
         this.AssociatedObject.Paste -= this.AssociatedObject_Paste;
     }
     this.AssociatedObject.GotFocus    -= this.AssociatedObject_GotFocus;
     this.AssociatedObject.LostFocus   -= this.AssociatedObject_LostFocus;
     this.AssociatedObject.TextChanged -= this.AssociatedObject_TextChanged;
 }
Exemplo n.º 26
0
        public ChatSearchMask()
        {
            InitializeComponent();

            if (ApiInformation.IsEventPresent("Windows.UI.Xaml.UIElement", "PreviewKeyDown"))
            {
                Field.PreviewKeyDown += OnKeyDown;
            }
            else
            {
                Field.KeyDown += OnKeyDown;
            }

            RegisterPropertyChangedCallback(VisibilityProperty, OnVisibilityChanged);
        }
        public void Initialize()
        {
#if WINDOWS_UWP
            var application = Application.Current;
            if (application != null)
            {
                if (ApiInformation.IsEventPresent("Windows.UI.Xaml.Application", "EnteredBackground"))
                {
                    application.EnteredBackground += OnEnteredBackground;
                }
                if (ApiInformation.IsEventPresent("Windows.UI.Xaml.Application", "LeavingBackground"))
                {
                    application.LeavingBackground += OnLeavingBackground;
                }
            }
#endif
        }
Exemplo n.º 28
0
        protected override void OnApplyTemplate()
        {
            TogglePaneButton = GetTemplateChild("TogglePaneButton") as Button;
            RootSplitView    = GetTemplateChild("RootSplitView") as SplitView;

            TogglePaneButton.Click += Toggle_Click;

            if (ApiInformation.IsEventPresent("Windows.UI.Xaml.Controls.SplitView", "PaneOpening"))
            {
                RootSplitView.PaneOpening += OnPaneOpening;
                RootSplitView.PaneClosing += OnPaneClosing;
            }
            else
            {
                RootSplitView.RegisterPropertyChangedCallback(SplitView.IsPaneOpenProperty, OnPaneOpenChanged);
            }
        }
Exemplo n.º 29
0
 public ShellRenderer()
 {
     Xamarin.Forms.Shell.VerifyShellUWPFlagEnabled(nameof(ShellRenderer));
     IsBackEnabled            = false;
     IsBackButtonVisible      = Microsoft.UI.Xaml.Controls.NavigationViewBackButtonVisible.Collapsed;
     IsSettingsVisible        = false;
     PaneDisplayMode          = Microsoft.UI.Xaml.Controls.NavigationViewPaneDisplayMode.LeftMinimal;
     IsPaneOpen               = false;
     Content                  = ItemRenderer = CreateShellItemRenderer();
     MenuItemTemplateSelector = CreateShellFlyoutTemplateSelector();
     if (ApiInformation.IsEventPresent("Windows.UI.Xaml.Controls.NavigationView", "PaneClosing"))
     {
         PaneClosing += (s, e) => OnPaneClosed();
     }
     if (ApiInformation.IsEventPresent("Windows.UI.Xaml.Controls.NavigationView", "PaneOpening"))
     {
         PaneOpening += (s, e) => OnPaneOpening();
     }
     ItemInvoked += OnMenuItemInvoked;
 }
Exemplo n.º 30
0
 public ShellRenderer()
 {
     Xamarin.Forms.Shell.VerifyShellUWPFlagEnabled(nameof(ShellRenderer));
     _flyoutBackdrop          = Brush.Default;
     IsSettingsVisible        = false;
     PaneDisplayMode          = Microsoft.UI.Xaml.Controls.NavigationViewPaneDisplayMode.LeftMinimal;
     IsPaneOpen               = false;
     Content                  = ItemRenderer = CreateShellItemRenderer();
     MenuItemTemplateSelector = CreateShellFlyoutTemplateSelector();
     if (ApiInformation.IsEventPresent("Windows.UI.Xaml.Controls.NavigationView", "PaneClosing"))
     {
         PaneClosing += (s, e) => OnPaneClosed();
     }
     if (ApiInformation.IsEventPresent("Windows.UI.Xaml.Controls.NavigationView", "PaneOpening"))
     {
         PaneOpening += (s, e) => OnPaneOpening();
     }
     ItemInvoked   += OnMenuItemInvoked;
     BackRequested += OnBackRequested;
     Style          = Windows.UI.Xaml.Application.Current.Resources["ShellNavigationView"] as Windows.UI.Xaml.Style;
 }