當前位置: 首頁>>代碼示例>>C#>>正文


C# VisualBrush.SetValue方法代碼示例

本文整理匯總了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));

            }
        }
開發者ID:madebysoren,項目名稱:NooSphere,代碼行數:61,代碼來源:Win7ColorTracking.cs


注:本文中的System.Windows.Media.VisualBrush.SetValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。