Esempio n. 1
0
        private async void Clipboard_Tapped(object sender, TappedRoutedEventArgs e)
        {
            FlashStoryboard.Begin();

            RenderTargetBitmap renderBitmap = new RenderTargetBitmap();
            uint width  = (uint)Carousel.ActualWidth + 1;
            uint height = (uint)Carousel.ActualHeight;

            Carousel.Measure(new Size(width, height));
            //Carousel.Arrange(new Rect(0, 0, width, height));

            await renderBitmap.RenderAsync(Carousel, (int)width, (int)height);

            var pixels = await renderBitmap.GetPixelsAsync();

            InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream()
            {
                Size = width * height * 4
            };
            BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.BmpEncoderId, stream);

            encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, (uint)renderBitmap.PixelWidth, (uint)renderBitmap.PixelHeight, 96d, 96d, pixels.ToArray());
            await encoder.FlushAsync();

            stream.Seek(0);

            var dataPackage = new DataPackage();

            dataPackage.SetBitmap(RandomAccessStreamReference.CreateFromStream(stream));

            Clipboard.SetContent(dataPackage);
        }
Esempio n. 2
0
        private void UpdateBar()
        {
            double valueScale = (MaxValue == 0) ? 0 : (double)this.Value / MaxValue;

            if (valueScale < 0)
            {
                valueScale = 0;
            }
            else if (valueScale > 1)
            {
                valueScale = 1;
            }
            ((ScaleTransform)HealthBar.RenderTransform).ScaleX = valueScale;

            if (valueScale == 1)
            {
                HealthBar.CornerRadius = new CornerRadius(5);
                DampedBar.CornerRadius = new CornerRadius(5);
            }
            else
            {
                HealthBar.CornerRadius = new CornerRadius(5, 0, 0, 5);
                DampedBar.CornerRadius = new CornerRadius(5, 0, 0, 5);
                FlashStoryboard.Begin();
            }
            if (valueScale > 0.6)
            {
                HealthBar.Background = LimeBrush;
            }
            else if (valueScale > 0.3)
            {
                HealthBar.Background = YellowBrush;
            }
            else
            {
                HealthBar.Background = RedBrush;
            }
            ((DoubleAnimation)DampStoryboard.Children[0]).To = valueScale;
            DampStoryboard.Begin();
        }