本文整理匯總了C#中Windows.UI.Xaml.Controls.Grid.GetVisual方法的典型用法代碼示例。如果您正苦於以下問題:C# Grid.GetVisual方法的具體用法?C# Grid.GetVisual怎麽用?C# Grid.GetVisual使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Windows.UI.Xaml.Controls.Grid
的用法示例。
在下文中一共展示了Grid.GetVisual方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
}
示例2: OnStructureChanged
private static void OnStructureChanged(DependencyObject d)
{
Rating c = (Rating)d;
if (c.EmptyImage == null)
{
c.EmptyImage = new Uri("ms-appx:///XamlBrewer.Uwp.RatingControl/Assets/defaultStar_empty.png");
}
if (c.FilledImage == null)
{
c.FilledImage = new Uri("ms-appx:///XamlBrewer.Uwp.RatingControl/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 options = new CompositionImageOptions()
{
DecodeWidth = c.ItemHeight,
DecodeHeight = c.ItemHeight
};
var imageFactory = CompositionImageFactory.CreateCompositionImageFactory(compositor);
var image = imageFactory.CreateImageFromUri(c.EmptyImage, options);
var emptyBrush = compositor.CreateSurfaceBrush(image.Surface);
image = imageFactory.CreateImageFromUri(c.FilledImage, options);
var fullBrush = compositor.CreateSurfaceBrush(image.Surface);
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 spriteVisual = compositor.CreateSpriteVisual();
spriteVisual.Size = new Vector2(c.ItemHeight, c.ItemHeight);
gridRoot.Children.InsertAtTop(spriteVisual);
spriteVisual.Brush = emptyBrush;
// Filled image.
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;
}
}
OnValueChanged(c);
}