Ejemplo n.º 1
0
 public void OnSetTargetButtonClicked(object sender, RoutedEventArgs args)
 {
     TeachingTip.SetAttach(this.targetButton, this.TeachingTip);
 }
        [TestProperty("TestPass:IncludeOnlyOn", "Desktop")] // TeachingTip doesn't appear to show up correctly in OneCore.
        public void TeachingTipBackgroundTest()
        {
            TeachingTip     teachingTip = null, teachingTipLightDismiss = null;
            SolidColorBrush blueBrush = null;
            Brush           lightDismissBackgroundBrush = null;
            var             loadedEvent = new AutoResetEvent(false);

            RunOnUIThread.Execute(() =>
            {
                Grid root           = new Grid();
                teachingTip         = new TeachingTip();
                teachingTip.Loaded += (object sender, RoutedEventArgs args) => { loadedEvent.Set(); };

                teachingTipLightDismiss = new TeachingTip();
                teachingTipLightDismiss.IsLightDismissEnabled = true;

                // Set LightDismiss background before show... it shouldn't take effect in the tree
                blueBrush = new SolidColorBrush(Colors.Blue);
                teachingTipLightDismiss.Background = blueBrush;

                root.Resources.Add("TeachingTip", teachingTip);
                root.Resources.Add("TeachingTipLightDismiss", teachingTipLightDismiss);

                lightDismissBackgroundBrush = MUXControlsTestApp.App.Current.Resources["TeachingTipTransientBackground"] as Brush;
                Verify.IsNotNull(lightDismissBackgroundBrush, "lightDismissBackgroundBrush");

                teachingTip.IsOpen             = true;
                teachingTipLightDismiss.IsOpen = true;

                MUXControlsTestApp.App.TestContentRoot = root;
            });

            IdleSynchronizer.Wait();
            loadedEvent.WaitOne();
            IdleSynchronizer.Wait();

            RunOnUIThread.Execute(() =>
            {
                var redBrush = new SolidColorBrush(Colors.Red);
                teachingTip.SetValue(TeachingTip.BackgroundProperty, redBrush);
                Verify.AreSame(redBrush, teachingTip.GetValue(TeachingTip.BackgroundProperty) as Brush);
                Verify.AreSame(redBrush, teachingTip.Background);

                teachingTip.Background = blueBrush;
                Verify.AreSame(blueBrush, teachingTip.Background);

                {
                    var popup      = TeachingTipTestHooks.GetPopup(teachingTip);
                    var child      = popup.Child;
                    var grandChild = VisualTreeHelper.GetChild(child, 0);
                    Verify.AreSame(blueBrush, ((Grid)grandChild).Background, "Checking TeachingTip.Background TemplateBinding works");
                }

                {
                    var popup       = TeachingTipTestHooks.GetPopup(teachingTipLightDismiss);
                    var child       = popup.Child;
                    var grandChild  = VisualTreeHelper.GetChild(child, 0);
                    var actualBrush = ((Grid)grandChild).Background;
                    Log.Comment("Checking LightDismiss TeachingTip Background is using resource for first invocation");
                    if (lightDismissBackgroundBrush != actualBrush)
                    {
                        if (actualBrush is SolidColorBrush actualSolidBrush)
                        {
                            string teachingTipMessage = $"LightDismiss TeachingTip Background is SolidColorBrush with color {actualSolidBrush.Color}";
                            Log.Comment(teachingTipMessage);
                            Verify.Fail(teachingTipMessage);
                        }
                        else
                        {
                            Verify.AreSame(lightDismissBackgroundBrush, actualBrush, "Checking LightDismiss TeachingTip Background is using resource for first invocation");
                        }
                    }
                }

                teachingTip.IsLightDismissEnabled = true;
            });

            IdleSynchronizer.Wait();

            RunOnUIThread.Execute(() =>
            {
                Verify.AreEqual(blueBrush.Color, ((SolidColorBrush)teachingTip.Background).Color);

                var popup      = TeachingTipTestHooks.GetPopup(teachingTip);
                var child      = popup.Child as Grid;
                var grandChild = VisualTreeHelper.GetChild(child, 0);
                var grandChildBackgroundBrush = ((Grid)grandChild).Background;
                //If we can no longer cast the background brush to a solid color brush then changing the
                //IsLightDismissEnabled has changed the background as we expected it to.
                if (grandChildBackgroundBrush is SolidColorBrush)
                {
                    Verify.AreNotEqual(blueBrush.Color, ((SolidColorBrush)grandChildBackgroundBrush).Color);
                }
            });
        }
 private void UWPPickerTip_Closed(Microsoft.UI.Xaml.Controls.TeachingTip sender, Microsoft.UI.Xaml.Controls.TeachingTipClosedEventArgs args)
 {
     PackageListViewSource.Clear();
 }
        private async void UWPPickerTip_ActionButtonClick(Microsoft.UI.Xaml.Controls.TeachingTip sender, object args)
        {
            try
            {
                if (PackageListView.SelectedItem is InstalledApplication Package)
                {
                    sender.IsOpen = false;
                    PickAppFlyout.Hide();

                    DisplayName.Text = Package.AppName;
                    Protocol.Text    = Package.AppFamilyName;
                    Icon.Source      = Package.Logo;

                    StorageFile FileThumbnail = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("FileThumbnail.png", CreationCollisionOption.ReplaceExisting);

                    if (Package.CreateStreamFromLogoData() is Stream LogoStream)
                    {
                        try
                        {
                            BitmapDecoder Decoder = await BitmapDecoder.CreateAsync(LogoStream.AsRandomAccessStream());

                            using (SoftwareBitmap SBitmap = await Decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied))
                                using (SoftwareBitmap ResizeBitmap = ComputerVisionProvider.ResizeToActual(SBitmap))
                                    using (InMemoryRandomAccessStream ResizeBitmapStream = new InMemoryRandomAccessStream())
                                    {
                                        BitmapEncoder Encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, ResizeBitmapStream);

                                        Encoder.SetSoftwareBitmap(ResizeBitmap);
                                        await Encoder.FlushAsync();

                                        BitmapImage Source = new BitmapImage();
                                        Icon.Source = Source;
                                        await Source.SetSourceAsync(ResizeBitmapStream);

                                        ResizeBitmapStream.Seek(0);

                                        using (Stream FileStream = await FileThumbnail.OpenStreamForWriteAsync())
                                        {
                                            await ResizeBitmapStream.AsStreamForRead().CopyToAsync(FileStream);
                                        }
                                    }
                        }
                        finally
                        {
                            LogoStream.Dispose();
                        }
                    }
                    else
                    {
                        Uri PageUri = AppThemeController.Current.Theme == ElementTheme.Dark ? new Uri("ms-appx:///Assets/Page_Solid_White.png") : new Uri("ms-appx:///Assets/Page_Solid_Black.png");

                        StorageFile PageFile = await StorageFile.GetFileFromApplicationUriAsync(PageUri);

                        using (IRandomAccessStream PageStream = await PageFile.OpenAsync(FileAccessMode.Read))
                        {
                            BitmapImage Image = new BitmapImage();
                            Icon.Source = Image;
                            await Image.SetSourceAsync(PageStream);

                            PageStream.Seek(0);

                            using (Stream TransformStream = PageStream.AsStreamForRead())
                                using (Stream FileStream = await FileThumbnail.OpenStreamForWriteAsync())
                                {
                                    await TransformStream.CopyToAsync(FileStream);
                                }
                        }
                    }

                    ImageFile = FileThumbnail;
                }
            }
            catch (Exception ex)
            {
                LogTracer.Log(ex);
                FailureTips.IsOpen = true;
            }
        }
 public void OnUntargetButtonClicked(object sender, RoutedEventArgs args)
 {
     TeachingTip.SetAttach(null, getTeachingTip());
 }