当前位置: 首页>>代码示例>>C#>>正文


C# CanvasDevice.Dispose方法代码示例

本文整理汇总了C#中CanvasDevice.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# CanvasDevice.Dispose方法的具体用法?C# CanvasDevice.Dispose怎么用?C# CanvasDevice.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CanvasDevice的用法示例。


在下文中一共展示了CanvasDevice.Dispose方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnStructureChanged

        private static async Task OnStructureChanged(DependencyObject d)
        {
            var c = (Rating)d;

            if (c.EmptyImage == null)
            {
                c.EmptyImage = new Uri("ms-appx:///XamlBrewer.Uwp.Rating/Assets/defaultStar_empty.png");
            }

            if (c.FilledImage == null)
            {
                c.FilledImage = new Uri("ms-appx:///XamlBrewer.Uwp.Rating/Assets/defaultStar_full.png");
            }

            if ((c.StepFrequency <= 0) || (c.StepFrequency > 1))
            {
                c.StepFrequency = 1;
            }

            var panel = c.GetTemplateChild(ItemsPartName) as StackPanel;
            if (panel != null)
            {
                // Load images.
                var root = panel.GetVisual();
                var compositor = root.Compositor;
                var canvasDevice = new CanvasDevice();
                var compositionDevice = CanvasComposition.CreateCompositionGraphicsDevice(compositor, canvasDevice);

                var rightPadding = c.ItemPadding;
                c.Clips.Clear();

                for (int i = 0; i < c.Maximum; i++)
                {
                    if (i == c.Maximum - 1)
                    {
                        rightPadding = 0;
                    }

                    // Create grid.
                    var grid = new Grid
                    {
                        Height = c.ItemHeight,
                        Width = c.ItemHeight,
                        Margin = new Thickness(0, 0, rightPadding, 0)
                    };
                    panel.Children.Add(grid);
                    var gridRoot = grid.GetVisual();

                    // Empty image.
                    var surface = await LoadFromUri(canvasDevice, compositionDevice, c.EmptyImage, new Size(c.ItemHeight, c.ItemHeight));
                    var emptyBrush = compositor.CreateSurfaceBrush(surface);
                    var spriteVisual = compositor.CreateSpriteVisual();
                    spriteVisual.Size = new Vector2(c.ItemHeight, c.ItemHeight);
                    gridRoot.Children.InsertAtTop(spriteVisual);
                    spriteVisual.Brush = emptyBrush;

                    // Filled image.
                    surface = await LoadFromUri(canvasDevice, compositionDevice, c.FilledImage, new Size(c.ItemHeight, c.ItemHeight));
                    var fullBrush = compositor.CreateSurfaceBrush(surface);
                    spriteVisual = compositor.CreateSpriteVisual();
                    spriteVisual.Size = new Vector2(c.ItemHeight, c.ItemHeight);
                    var clip = compositor.CreateInsetClip();
                    c.Clips.Add(clip);
                    spriteVisual.Clip = clip;
                    gridRoot.Children.InsertAtTop(spriteVisual);
                    spriteVisual.Brush = fullBrush;
                }

                compositionDevice.Dispose();
                canvasDevice.Dispose();
            }

            OnValueChanged(c);
        }
开发者ID:XamlBrewer,项目名称:UWP-Composition-Rating-Control,代码行数:74,代码来源:Rating.cs


注:本文中的CanvasDevice.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。