Beispiel #1
0
 protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
 {
     if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Media.Imaging.BitmapImage", nameof(BitmapImage.IsAnimatedBitmap)))
     {
         return(AfterAnniversary);
     }
     else
     {
         return(BeforeAnniversary);
     }
 }
Beispiel #2
0
        async void LaunchAd()
        {
            var uri     = new Uri("https://microsoft.com/surface");
            var options = new LauncherOptions();

            // Set the grouping preference if running on a system that supports it.
            if (ApiInformation.IsPropertyPresent(typeof(LauncherOptions).FullName, "GroupingPreference"))
            {
                options.GroupingPreference = ViewGrouping.Separate;
            }
            await Launcher.LaunchUriAsync(uri, options);
        }
 /// <summary>
 /// Checks to see if the requested property is present on the current platform.
 /// </summary>
 /// <param name="type">The <see cref="Type"/> of the class to check.</param>
 /// <param name="propertyName">The name of the method (ex: "Eyes").</param>
 /// <returns>True if the property is available and can be called. Otherwise, false.</returns>
 public static bool IsPropertyAvailable(Type type, string propertyName)
 {
     if (type == null || string.IsNullOrWhiteSpace(type.FullName))
     {
         throw new ArgumentException();
     }
     if (string.IsNullOrWhiteSpace(propertyName))
     {
         throw new ArgumentException();
     }
     return(ApiInformation.IsPropertyPresent(type.FullName, propertyName));
 }
Beispiel #4
0
 public ShareCodeDialog()
 {
     this.InitializeComponent();
     if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.ContentDialog", "DefaultButton"))
     {
         this.DefaultButton = ContentDialogButton.Primary;
     }
     if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.ContentDialog", "CloseButtonText"))
     {
         this.CloseButtonText = "关闭";
     }
 }
Beispiel #5
0
        private void CreateKeyboardAccelerator(Windows.System.VirtualKey key, Windows.System.VirtualKeyModifiers modifiers = Windows.System.VirtualKeyModifiers.Control)
        {
            if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.UIElement", "KeyboardAccelerators"))
            {
                var accelerator = new KeyboardAccelerator {
                    Modifiers = modifiers, Key = key, ScopeOwner = this
                };
                accelerator.Invoked += FlyoutAccelerator_Invoked;

                Transport.KeyboardAccelerators.Add(accelerator);
            }
        }
Beispiel #6
0
        private void Dispose()
        {
            Element2.Reset();
            Element0.Reset();
            Element1.Reset();

            if (_surface != null)
            {
                _surface.Children.Remove(_mediaPlayerElement);
                _surface = null;
            }

            if (_streamingInterop != null)
            {
                var interop = _streamingInterop;
                _streamingInterop = null;

                Task.Run(() => interop?.Dispose());
            }

            if (_mediaPlayer != null)
            {
                _mediaPlayer.VolumeChanged -= OnVolumeChanged;
                _mediaPlayer.SourceChanged -= OnSourceChanged;
                _mediaPlayer.MediaOpened   -= OnMediaOpened;
                _mediaPlayer.PlaybackSession.PlaybackStateChanged -= OnPlaybackStateChanged;

                _mediaPlayerElement.SetMediaPlayer(null);
                //_mediaPlayerElement.AreTransportControlsEnabled = false;
                //_mediaPlayerElement.TransportControls = null;
                //_mediaPlayerElement = null;

                if (_compactLifetime == null)
                {
                    _mediaPlayer.Dispose();
                    _mediaPlayer = null;
                }

                OnSourceChanged();
            }

            if (_request != null)
            {
                _request.RequestRelease();
                _request = null;
            }

            if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.MediaTransportControls", "ShowAndHideAutomatically"))
            {
                Transport.ShowAndHideAutomatically = false;
            }
        }
 public IsScreenCaptureEnabledTests()
 {
     this.InitializeComponent();
     if (ApiInformation.IsPropertyPresent("Windows.UI.ViewManagement.ApplicationView", "IsScreenCaptureEnabled"))
     {
         CaptureCheckBox.IsChecked = ApplicationView.GetForCurrentView().IsScreenCaptureEnabled;
     }
     else
     {
         InfoMessage.Text          = "API not supported on this platform.";
         CaptureCheckBox.IsEnabled = false;
     }
 }
Beispiel #8
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var device = e.Parameter as DeviceInformation;

            _deviceID = device.Id;
            DeviceNamePlaceHolder.Text = device.Name;

            if (DeviceHelper.GetDeviceType() == DeviceTypeEnum.Xbox &&
                ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.Control", "XYFocusLeft"))
            {
                OkButton.XYFocusLeft = Select;
            }
        }
Beispiel #9
0
        public ScrollPreviewItemTemplate()
        {
            this.InitializeComponent();

            if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.TextBlock", nameof(TextBlock.HorizontalTextAlignment)))
            {
                Main_TextBlock.HorizontalTextAlignment = TextAlignment.Center;
            }
            else
            {
                Main_TextBlock.HorizontalAlignment = HorizontalAlignment.Center;
            }
        }
 public static void ExecuteIfPropertyPresent(string typeName, string propertyName, Action action)
 {
     if (ApiInformation.IsPropertyPresent(typeName, propertyName))
     {
         try
         {
             action();
         }
         catch (MissingMethodException)
         {
         }
     }
 }
Beispiel #11
0
        public LoginLibraryDialog()
        {
            this.InitializeComponent();

            UsernameTextBox.Text     = Convert.ToString(localSettings.Values[AppConstants.LIBRARY_USERNAME_SETTINGS]);
            PasswordTextBox.Password = Convert.ToString(localSettings.Values[AppConstants.LIBRARY_PASSWORD_SETTINGS]);
            RememberCheck.IsChecked  = true;

            if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.ContentDialog", "DefaultButton"))
            {
                this.DefaultButton = ContentDialogButton.Primary;
            }
        }
Beispiel #12
0
        public double DiagonalSizeInInches()
        {
            var di = DisplayInformation.GetForCurrentView();

            if (ApiInformation.IsPropertyPresent(typeof(DisplayInformation).ToString(), nameof(di.DiagonalSizeInInches)))
            {
                return(di.DiagonalSizeInInches.Value);
            }
            else
            {
                return(7);
            }
        }
        private GalleryView()
        {
            InitializeComponent();

            #region Localizations

            FlyoutSaveAs.Text = Strings.Additional.SaveAs;

            #endregion

            if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.UIElement", "KeyboardAccelerators"))
            {
                FlyoutSaveAs.KeyboardAccelerators.Add(new KeyboardAccelerator {
                    Modifiers = Windows.System.VirtualKeyModifiers.Control, Key = Windows.System.VirtualKey.S, ScopeOwner = this
                });
            }

            Layer.Visibility = Visibility.Collapsed;

            _layer = ElementCompositionPreview.GetElementVisual(Layer);

            _mediaPlayerElement = new MediaPlayerElement {
                Style = Resources["TransportLessMediaPlayerStyle"] as Style
            };
            _mediaPlayerElement.AreTransportControlsEnabled = true;
            _mediaPlayerElement.TransportControls           = Transport;
            _mediaPlayerElement.SetMediaPlayer(_mediaPlayer);

            Initialize();

            if (ApiInformation.IsMethodPresent("Windows.UI.Xaml.Hosting.ElementCompositionPreview", "SetImplicitShowAnimation"))
            {
                var easing   = ConnectedAnimationService.GetForCurrentView().DefaultEasingFunction;
                var duration = ConnectedAnimationService.GetForCurrentView().DefaultDuration;

                var layerShowAnimation = Window.Current.Compositor.CreateScalarKeyFrameAnimation();
                layerShowAnimation.InsertKeyFrame(0.0f, 0.0f, easing);
                layerShowAnimation.InsertKeyFrame(1.0f, 1.0f, easing);
                layerShowAnimation.Target   = nameof(Visual.Opacity);
                layerShowAnimation.Duration = duration;

                var layerHideAnimation = Window.Current.Compositor.CreateScalarKeyFrameAnimation();
                layerHideAnimation.InsertKeyFrame(0.0f, 1.0f, easing);
                layerHideAnimation.InsertKeyFrame(1.0f, 0.0f, easing);
                layerHideAnimation.Target   = nameof(Visual.Opacity);
                layerHideAnimation.Duration = duration;

                ElementCompositionPreview.SetImplicitShowAnimation(Layer, layerShowAnimation);
                ElementCompositionPreview.SetImplicitHideAnimation(Layer, layerHideAnimation);
            }
        }
Beispiel #14
0
 public ImageModel(string source, bool autoPlay = true)
 {
     SourceUri = source;
     if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Media.Imaging.BitmapImage", nameof(BitmapImage.IsAnimatedBitmap)))
     {
         Image                   = new BitmapImage(new Uri(source));
         Image.AutoPlay          = autoPlay;
         Image.DownloadProgress += Image_DownloadProgress;
     }
     else
     {
         ProgressVisibility = Visibility.Collapsed;
     }
 }
Beispiel #15
0
        private async Task AskForReview()
        {
            object hasGivenReviewObject = ApplicationData.Current.RoamingSettings.Values["HasGivenReview"];
            bool   hasGivenReview       = hasGivenReviewObject is bool b && b;

            if (!hasGivenReview)
            {
                object popupRefusedCountObject = ApplicationData.Current.RoamingSettings.Values["popupRefusedCount"];
                int    popupRefusedCount       = popupRefusedCountObject is int i ? i : 1;
                if (popupRefusedCount > 1)
                {
                    Random rng = new Random();
                    if (rng.NextDouble() > 1.0 / popupRefusedCount)
                    {
                        return;
                    }
                }

                ContentDialog wantToReviewDialog = new ContentDialog
                {
                    Title             = "Are you liking MDF to ISO?",
                    Content           = "Please consider to leave a feedback on the Store",
                    PrimaryButtonText = "Rate now",
                };

                if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.ContentDialog",
                                                     nameof(ContentDialog.CloseButtonText)))
                {
                    wantToReviewDialog.CloseButtonText = "Later";
                }
                else
                {
                    wantToReviewDialog.SecondaryButtonText = "Later";
                }

                ContentDialogResult result = await wantToReviewDialog.ShowAsync();

                if (result == ContentDialogResult.Primary)
                {
                    bool reviewResult = await ShowRatingReviewDialog();

                    ApplicationData.Current.RoamingSettings.Values["HasGivenReview"] = reviewResult;
                }
                else
                {
                    logger.Log("Review.Refused");
                    ApplicationData.Current.RoamingSettings.Values["popupRefusedCount"] = popupRefusedCount + 1;
                }
            }
        }
Beispiel #16
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>
        public App()
        {
            InitializeComponent();
            Suspending += OnSuspending;

            //API check to ensure the "RequiresPointerMode" property exists, ensuring project is running on build 14393 or later
            if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Application", "RequiresPointerMode"))
            {
                if (IsXbox())
                {
                    Current.RequiresPointerMode = ApplicationRequiresPointerMode.WhenRequested;
                }
            }
        }
Beispiel #17
0
        public async Task When_IsPropertyPresent_Called_Twice()
        {
            // Verifies fix for issue #4803
            // SharedHelpers called IsPropertyPresent twice for an implemented property
            // but the second call resulted in false

            // Application.Current is implemented on all targets
            var isPresent = ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Application", "Current");

            Assert.IsTrue(isPresent);
            var secondIsPresent = ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Application", "Current");

            Assert.IsTrue(secondIsPresent);
        }
Beispiel #18
0
        public DefaultScreenSizeProvider()
        {
            if (!ApiInformation.IsPropertyPresent(typeof(DisplayInformation).FullName, "ScreenHeightInRawPixels") ||
                !ApiInformation.IsPropertyPresent(typeof(DisplayInformation).FullName, "ScreenWidthInRawPixels"))
            {
                AppCenterLog.Warn(AppCenterLog.LogTag, FailureMessage);
                _displayInformationEventSemaphore.Release();
                return;
            }

            // Only try to get screen size once resuming event is invoked, because there's no point
            // in trying beforehand.
            ApplicationLifecycleHelper.Instance.ApplicationResuming += SetUpDisplayInformation;
        }
        public Task <WebTokenRequest> CreateWebTokenRequestAsync(
            WebAccountProvider provider,
            AuthenticationRequestParameters authenticationRequestParameters,
            bool isForceLoginPrompt,
            bool isInteractive,
            bool isAccountInWam,
            string scopeOverride = null)
        {
            string loginHint = !string.IsNullOrEmpty(authenticationRequestParameters.LoginHint) ?
                               authenticationRequestParameters.LoginHint :
                               authenticationRequestParameters.Account?.Username;

            bool setLoginHint =
                isInteractive &&
                !isAccountInWam &&
                !string.IsNullOrEmpty(loginHint);

            var wamPrompt = setLoginHint || (isInteractive && isForceLoginPrompt) ?
                            WebTokenRequestPromptType.ForceAuthentication :
                            WebTokenRequestPromptType.Default;

            WebTokenRequest request = new WebTokenRequest(
                provider,
                scopeOverride ?? ScopeHelper.GetMsalScopes(authenticationRequestParameters.Scope).AsSingleString(),
                authenticationRequestParameters.AppConfig.ClientId,
                wamPrompt);

            if (setLoginHint)
            {
                request.Properties.Add("LoginHint", authenticationRequestParameters.LoginHint);
            }

            request.Properties.Add("wam_compat", "2.0");
            if (ApiInformation.IsPropertyPresent("Windows.Security.Authentication.Web.Core.WebTokenRequest", "CorrelationId"))
            {
                LegacyOsWamProxy.SetCorrelationId(request, authenticationRequestParameters.CorrelationId.ToString());
            }
            else
            {
                request.Properties.Add("correlationId", authenticationRequestParameters.CorrelationId.ToString());
            }

            if (!string.IsNullOrEmpty(authenticationRequestParameters.ClaimsAndClientCapabilities))
            {
                request.Properties.Add("claims", authenticationRequestParameters.ClaimsAndClientCapabilities);
            }

            return(Task.FromResult(request));
        }
        public ScreenProperties GetProperties()
        {
            var di         = DisplayInformation.GetForCurrentView();
            var properties = new ScreenProperties
            {
                Density = di.RawPixelsPerViewPixel
            };

            if (ApiInformation.IsPropertyPresent(typeof(DisplayInformation).FullName, nameof(DisplayInformation.ScreenWidthInRawPixels)))
            {
                properties.PixelWidth  = (int)di.ScreenWidthInRawPixels;
                properties.PixelHeight = (int)di.ScreenHeightInRawPixels;
            }
            return(properties);
        }
Beispiel #21
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (DeviceHelper.GetDeviceType() == DeviceTypeEnum.Xbox &&
                ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.Control", nameof(XYFocusDown)))
            {
                ZoomCombobox.XYFocusDown     = SpeedResetButton;
                SpeedRateSlider.XYFocusDown  = AudioDelayResetButton;
                SpeedRateSlider.XYFocusUp    = SpeedResetButton;
                AudioDelaySlider.XYFocusDown = SubtitleDelayResetButton;
                AudioDelaySlider.XYFocusUp   = AudioDelayResetButton;
                SpuDelaySlider.XYFocusUp     = SubtitleDelayResetButton;
            }
        }
Beispiel #22
0
 public void Close()
 {
     CancelSpeech();
     if (ApiInformation.IsPropertyPresent("Windows.Media.Playback.MediaPlayer", "PlaybackSession"))
     {
         player.PlaybackSession.PlaybackStateChanged -= OnPlaybackStateChanged;
     }
     else
     {
         player.CurrentStateChanged -= OnPlaybackStateChanged;
     }
     player.MediaEnded  -= OnMediaEnded;
     player.MediaFailed -= OnPlayerMediaFaild;
     State = OcSynthState.Ready;
 }
        void UpdatePresence()
        {
            if (string.IsNullOrEmpty(_typeName) || string.IsNullOrEmpty(_propertyName))
            {
                // State trigger not yet fully initialized.
                return;
            }

            // If the answer is not already cached, then call into
            // ApiInformation method to determine whether property is present.
            _isPropertyPresent = propertyPresence.GetOrAdd(Tuple.Create(_typeName, _propertyName),
                                                           (key) => ApiInformation.IsPropertyPresent(key.Item1, key.Item2));

            UpdateState();
        }
        public static T ExecuteIfPropertyPresent <T>(string typeName, string propertyName, Func <T> action)
        {
            if (ApiInformation.IsPropertyPresent(typeName, propertyName))
            {
                try
                {
                    return(action());
                }
                catch (MissingMethodException)
                {
                }
            }

            return(default(T));
        }
        private static ScheduledToastNotification GenerateScheduledToastNotification(XmlDocument xml, DateTime startTime, string id, string remoteId)
        {
            var notif = new ScheduledToastNotification(xml, startTime)
            {
                Id = id
            };

            // If RemoteId property is present
            if (remoteId != null && ApiInformation.IsPropertyPresent(typeof(ScheduledToastNotification).FullName, nameof(ScheduledToastNotification.RemoteId)))
            {
                notif.RemoteId = remoteId;
            }

            return(notif);
        }
Beispiel #26
0
        public SettingsPrivacyShowForwardedPage()
        {
            InitializeComponent();
            Title = Strings.Resources.PrivacyForwards;

            if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.UIElement", "Shadow"))
            {
                var themeShadow = new ThemeShadow();
                ToolTip.Shadow       = themeShadow;
                ToolTip.Translation += new Vector3(0, 0, 32);

                themeShadow.Receivers.Add(BackgroundPresenter);
                themeShadow.Receivers.Add(MessagePreview);
            }
        }
Beispiel #27
0
        public StickerPanel()
        {
            InitializeComponent();
            DataContext = new object();

            var shadow1 = DropShadowEx.Attach(HeaderSeparator, 20, 0.25f);

            HeaderSeparator.SizeChanged += (s, args) =>
            {
                shadow1.Size = args.NewSize.ToVector2();
            };

            var protoService = TLContainer.Current.Resolve <IProtoService>();

            AnimationsRoot.DataContext           = AnimationDrawerViewModel.GetForCurrentView(protoService.SessionId);
            AnimationsRoot.ItemClick             = Animations_ItemClick;
            AnimationsRoot.ItemContextRequested += (s, args) => AnimationContextRequested?.Invoke(s, args);

            StickersRoot.DataContext           = StickerDrawerViewModel.GetForCurrentView(protoService.SessionId);
            StickersRoot.ItemClick             = Stickers_ItemClick;
            StickersRoot.ItemContextRequested += (s, args) => StickerContextRequested?.Invoke(s, args);

            EmojisRoot.DataContext = StickersRoot.DataContext;

            switch (SettingsService.Current.Stickers.SelectedTab)
            {
            case StickersTab.Emoji:
                Pivot.SelectedIndex = 0;
                break;

            case StickersTab.Animations:
                Pivot.SelectedIndex = 1;
                break;

            case StickersTab.Stickers:
                Pivot.SelectedIndex = 2;
                break;
            }

            if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.UIElement", "Shadow"))
            {
                var themeShadow = new ThemeShadow();
                BackgroundElement.Shadow       = themeShadow;
                BackgroundElement.Translation += new Vector3(0, 0, 32);

                themeShadow.Receivers.Add(ShadowElement);
            }
        }
Beispiel #28
0
        public void BitmapIconSourceTest()
        {
            BitmapIconSource iconSource = null;
            BitmapIcon       bitmapIcon = null;
            var uri = new Uri("ms-appx:///Assets/ingredient1.png");

            RunOnUIThread.Execute(() =>
            {
                iconSource = new BitmapIconSource();
                bitmapIcon = iconSource.CreateIconElement() as BitmapIcon;

                // IconSource.Foreground should be null to allow foreground inheritance from
                // the parent to work.
                Verify.AreEqual(iconSource.Foreground, null);
                //Verify.AreEqual(bitmapIcon.Foreground, null);

                Log.Comment("Validate the defaults match BitmapIcon.");

                var icon = new BitmapIcon();
                Verify.AreEqual(icon.UriSource, iconSource.UriSource);
                Verify.AreEqual(bitmapIcon.UriSource, iconSource.UriSource);

                if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.BitmapIcon", "ShowAsMonochrome"))
                {
                    Verify.AreEqual(icon.ShowAsMonochrome, iconSource.ShowAsMonochrome);
                    Verify.AreEqual(bitmapIcon.ShowAsMonochrome, iconSource.ShowAsMonochrome);
                }

                Log.Comment("Validate that you can change the properties.");

                iconSource.Foreground       = new SolidColorBrush(Windows.UI.Colors.Red);
                iconSource.UriSource        = uri;
                iconSource.ShowAsMonochrome = false;
            });
            IdleSynchronizer.Wait();

            RunOnUIThread.Execute(() =>
            {
                Verify.IsTrue(iconSource.Foreground is SolidColorBrush);
                Verify.IsTrue(bitmapIcon.Foreground is SolidColorBrush);
                Verify.AreEqual(Windows.UI.Colors.Red, (iconSource.Foreground as SolidColorBrush).Color);
                Verify.AreEqual(Windows.UI.Colors.Red, (bitmapIcon.Foreground as SolidColorBrush).Color);
                Verify.AreEqual(uri, iconSource.UriSource);
                Verify.AreEqual(uri, bitmapIcon.UriSource);
                Verify.AreEqual(false, iconSource.ShowAsMonochrome);
                Verify.AreEqual(false, bitmapIcon.ShowAsMonochrome);
            });
        }
Beispiel #29
0
        async void LaunchFlightUri(Hyperlink sender, HyperlinkClickEventArgs e)
        {
            var parent = (FrameworkElement)VisualTreeHelper.GetParent(sender);
            var uri    = (Uri)parent.Tag;

            if (uri != null)
            {
                var options = new LauncherOptions();
                // Set the grouping preference if running on a system that supports it.
                if (ApiInformation.IsPropertyPresent(typeof(LauncherOptions).FullName, "GroupingPreference"))
                {
                    options.GroupingPreference = ViewGrouping.WithSource;
                }
                await Launcher.LaunchUriAsync(uri, options);
            }
        }
Beispiel #30
0
        public void DoesAdvertiseSupportedEvents()
        {
            if (!ApiInformation.IsPropertyPresent("Windows.UI.Xaml.UIElement", "Interactions"))
            {
                Log.Warning("UIElement.Interactions not supported on this build.");
                return;
            }

            RunOnUIThread.Execute(() =>
            {
                var interaction     = new SliderInteraction();
                var supportedEvents = interaction.GetSupportedEvents();

                Verify.IsGreaterThan(supportedEvents.Count, 0);
            });
        }