本文整理汇总了C#中System.Windows.Media.VisualBrush.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# VisualBrush.SetValue方法的具体用法?C# VisualBrush.SetValue怎么用?C# VisualBrush.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.VisualBrush
的用法示例。
在下文中一共展示了VisualBrush.SetValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Win7ColorHotTrackExtenssion_Loaded
/// <summary>
/// Load event
/// </summary>
/// <param name="sender">The control sender of the change</param>
/// <param name="e">the parameters for the RoutedEvent</param>
static void Win7ColorHotTrackExtenssion_Loaded(object sender, RoutedEventArgs e)
{
// As stated before, it will not work if the element is not a content control so an exception is thrown
if (!(sender is ContentControl))
throw new NotSupportedException("This attached property is just supported by an ContentControl");
var control = (ContentControl)sender;
// verify if any data is binded to the Tag property, because if it is, we dont want to lose it
if (control.GetValue(FrameworkElement.TagProperty) == null)
{
// Instantiate and Invalidate the VisualBrush needed for the analisys of the content
VisualBrush b = new VisualBrush();
b.SetValue(VisualBrush.VisualProperty, ((StackPanel)control.Content).Children[0]);
control.InvalidateVisual();
// if the control has no visual (with a height lesser or equal to zero)
// we dont need to perform any action, couse the result will be a transparent brush anyway
if ((control as FrameworkElement).ActualHeight <= 0)
return;
// Render the visual of the element to an bitmap with the RenderTargetBitmap class
RenderTargetBitmap RenderBmp = null;
try
{
RenderBmp = new RenderTargetBitmap(
(int)(((StackPanel)control.Content).Children[0] as FrameworkElement).Width,
(int)(((StackPanel)control.Content).Children[0] as FrameworkElement).Height,
96,
96,
PixelFormats.Pbgra32);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
RenderBmp.Render(b.Visual);
// Set the value to the Tag property
control.SetValue(FrameworkElement.TagProperty, RenderBmp);
control.Background = Brushes.LightBlue;
// Instanciate and initialize a Binding element to handle the new tag property
Binding bindBG = new Binding("Tag");
bindBG.Source = control;
// Define the converter that will be used to handle the transformation from an image to average color
bindBG.Converter = new IconToAvgColorBrushConverter();
// Set the binding to the Background property
control.SetBinding(ContentControl.BackgroundProperty, bindBG);
control.SetValue(ContentControl.BorderBrushProperty, new SolidColorBrush(Colors.White));
}
}