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


C# Brush.GetType方法代碼示例

本文整理匯總了C#中Windows.UI.Xaml.Media.Brush.GetType方法的典型用法代碼示例。如果您正苦於以下問題:C# Brush.GetType方法的具體用法?C# Brush.GetType怎麽用?C# Brush.GetType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Windows.UI.Xaml.Media.Brush的用法示例。


在下文中一共展示了Brush.GetType方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: IsEqualTo

        /// <summary>
        /// Verifies if the given brush is the same as the otherBrush.
        /// </summary>
        /// <param name="brush">Brush</param>
        /// <param name="otherBrush">Brush</param>
        /// <returns>true if yes, otherwise false</returns>
        public static bool IsEqualTo(this Brush brush, Brush otherBrush)
        {
            if (brush.GetType() != otherBrush.GetType())
                return false;

            if (ReferenceEquals(brush, otherBrush))
                return true;

            // Are both instances of SolidColorBrush
            var solidBrushA = brush as SolidColorBrush;
            var solidBrushB = otherBrush as SolidColorBrush;
            if ((solidBrushA != null) && (solidBrushB != null))
            {
                return (solidBrushA.Color == solidBrushB.Color)
                       && solidBrushA.Opacity.IsCloseTo(solidBrushB.Opacity);
            }

            // Are both instances of LinearGradientBrush
            var linGradBrushA = brush as LinearGradientBrush;
            var linGradBrushB = otherBrush as LinearGradientBrush;

            if ((linGradBrushA != null) && (linGradBrushB != null))
            {
                var result = (linGradBrushA.ColorInterpolationMode == linGradBrushB.ColorInterpolationMode)
                               && (linGradBrushA.EndPoint == linGradBrushB.EndPoint)
                               && (linGradBrushA.MappingMode == linGradBrushB.MappingMode)
                               && linGradBrushA.Opacity.IsCloseTo(linGradBrushB.Opacity)
                               && (linGradBrushA.StartPoint == linGradBrushB.StartPoint)
                               && (linGradBrushA.SpreadMethod == linGradBrushB.SpreadMethod)
                               && (linGradBrushA.GradientStops.Count == linGradBrushB.GradientStops.Count);
                if (!result)
                    return false;

                for (var i = 0; i < linGradBrushA.GradientStops.Count; i++)
                {
                    result = (linGradBrushA.GradientStops[i].Color == linGradBrushB.GradientStops[i].Color)
                             && linGradBrushA.GradientStops[i].Offset.IsCloseTo(linGradBrushB.GradientStops[i].Offset);

                    if (!result)
                        break;
                }

                return result;
            }

            // Are both instances of RadialGradientBrush
            //var radGradBrushA = brush as RadialGradientBrush;
            //var radGradBrushB = otherBrush as RadialGradientBrush;

            //if ((radGradBrushA != null) && (radGradBrushB != null))
            //{
            //    var result = (radGradBrushA.ColorInterpolationMode == radGradBrushB.ColorInterpolationMode)
            //                 && (radGradBrushA.GradientOrigin == radGradBrushB.GradientOrigin)
            //                 && (radGradBrushA.MappingMode == radGradBrushB.MappingMode)
            //                 && radGradBrushA.Opacity.IsCloseTo(radGradBrushB.Opacity)
            //                 && radGradBrushA.RadiusX.IsCloseTo(radGradBrushB.RadiusX)
            //                 && radGradBrushA.RadiusY.IsCloseTo(radGradBrushB.RadiusY)
            //                 && (radGradBrushA.SpreadMethod == radGradBrushB.SpreadMethod)
            //                 && (radGradBrushA.GradientStops.Count == radGradBrushB.GradientStops.Count);

            //    if (!result)
            //        return false;

            //    for (var i = 0; i < radGradBrushA.GradientStops.Count; i++)
            //    {
            //        result = (radGradBrushA.GradientStops[i].Color == radGradBrushB.GradientStops[i].Color)
            //                 && radGradBrushA.GradientStops[i].Offset.IsCloseTo(radGradBrushB.GradientStops[i].Offset);

            //        if (!result)
            //            break;
            //    }

            //    return result;
            //}

            // Are both instances of ImageBrush
            var imgBrushA = brush as ImageBrush;
            var imgBrushB = otherBrush as ImageBrush;
            if ((imgBrushA != null) && (imgBrushB != null))
            {
                var result = (imgBrushA.AlignmentX == imgBrushB.AlignmentX)
                              && (imgBrushA.AlignmentY == imgBrushB.AlignmentY)
                              && imgBrushA.Opacity.IsCloseTo(imgBrushB.Opacity)
                              && (imgBrushA.Stretch == imgBrushB.Stretch)
                              //&& (imgBrushA.TileMode == imgBrushB.TileMode)
                              //&& (imgBrushA.Viewbox == imgBrushB.Viewbox)
                              //&& (imgBrushA.ViewboxUnits == imgBrushB.ViewboxUnits)
                              //&& (imgBrushA.Viewport == imgBrushB.Viewport)
                              //&& (imgBrushA.ViewportUnits == imgBrushB.ViewportUnits)
                              && (imgBrushA.ImageSource == imgBrushB.ImageSource);

                return result;
            }

//.........這裏部分代碼省略.........
開發者ID:RareNCool,項目名稱:CompositionProToolkit,代碼行數:101,代碼來源:Utils.cs


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