Advertisement
Guest User

MAsk converter for a dual header groupbox

a guest
May 31st, 2011
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.75 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Data;
  6. using System.Windows.Media;
  7. using System.Windows.Shapes;
  8.  
  9. namespace Velib.Converters
  10. {
  11.     public class DualBorderGapMaskConverter : IMultiValueConverter
  12.     {
  13.         // Methods
  14.         public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
  15.         {
  16.             double num4;
  17.             Type type = typeof(double);
  18.             if (parameter == null
  19.                 || values == null
  20.                 || values.Length != 4
  21.                 || values[0] == null
  22.                 || values[1] == null
  23.                 || values[2] == null
  24.                 || values[3] == null
  25.                 || !type.IsAssignableFrom(values[0].GetType())
  26.                 || !type.IsAssignableFrom(values[1].GetType())
  27.                 || !type.IsAssignableFrom(values[2].GetType())
  28.                 || !type.IsAssignableFrom(values[3].GetType()))
  29.             {
  30.                 return DependencyProperty.UnsetValue;
  31.             }
  32.             Type c = parameter.GetType();
  33.             if (!type.IsAssignableFrom(c) && !typeof(string).IsAssignableFrom(c))
  34.             {
  35.                 return DependencyProperty.UnsetValue;
  36.             }
  37.             double pixels1 = (double)values[0];
  38.             double pixels2 = (double)values[1];
  39.             double width = (double)values[2];
  40.             double height = (double)values[3];
  41.             if ((width == 0.0) || (height == 0.0))
  42.             {
  43.                 return null;
  44.             }
  45.             if (parameter is string)
  46.             {
  47.                 num4 = double.Parse((string)parameter, NumberFormatInfo.InvariantInfo);
  48.             }
  49.             else
  50.             {
  51.                 num4 = (double)parameter;
  52.             }
  53.             Grid visual = new Grid();
  54.             visual.Width = width;
  55.             visual.Height = height;
  56.             ColumnDefinition colDefinition1 = new ColumnDefinition();
  57.             ColumnDefinition colDefinition2 = new ColumnDefinition();
  58.             ColumnDefinition colDefinition3 = new ColumnDefinition();
  59.             ColumnDefinition colDefinition4 = new ColumnDefinition();
  60.             ColumnDefinition colDefinition5 = new ColumnDefinition();
  61.             colDefinition1.Width = new GridLength(num4);
  62.             colDefinition2.Width = new GridLength(pixels1);
  63.             colDefinition3.Width = new GridLength(1.0, GridUnitType.Star);
  64.             colDefinition4.Width = new GridLength(pixels2);
  65.             colDefinition5.Width = new GridLength(num4);
  66.             visual.ColumnDefinitions.Add(colDefinition1);
  67.             visual.ColumnDefinitions.Add(colDefinition2);
  68.             visual.ColumnDefinitions.Add(colDefinition3);
  69.             visual.ColumnDefinitions.Add(colDefinition4);
  70.             visual.ColumnDefinitions.Add(colDefinition5);
  71.             RowDefinition rowDefinition1 = new RowDefinition();
  72.             RowDefinition rowDefinition2 = new RowDefinition();
  73.             rowDefinition1.Height = new GridLength(height / 2.0);
  74.             rowDefinition2.Height = new GridLength(1.0, GridUnitType.Star);
  75.             visual.RowDefinitions.Add(rowDefinition1);
  76.             visual.RowDefinitions.Add(rowDefinition2);
  77.             Rectangle rectangle1 = new Rectangle();
  78.             Rectangle rectangle2 = new Rectangle();
  79.             Rectangle rectangle3 = new Rectangle();
  80.             Rectangle rectangle4 = new Rectangle();
  81.             Rectangle rectangle5 = new Rectangle();
  82.             rectangle1.Fill = Brushes.Black;
  83.             rectangle2.Fill = Brushes.Black;
  84.             rectangle3.Fill = Brushes.Black;
  85.             rectangle4.Fill = Brushes.Black;
  86.             rectangle5.Fill = Brushes.Black;
  87.             Grid.SetRowSpan(rectangle1, 2);
  88.             Grid.SetRow(rectangle1, 0);
  89.             Grid.SetColumn(rectangle1, 0);
  90.             Grid.SetRow(rectangle2, 1);
  91.             Grid.SetColumn(rectangle2, 1);
  92.             Grid.SetRowSpan(rectangle3, 2);
  93.             Grid.SetRow(rectangle3, 0);
  94.             Grid.SetColumn(rectangle3, 2);
  95.             Grid.SetRow(rectangle4, 1);
  96.             Grid.SetColumn(rectangle4, 3);
  97.             Grid.SetRowSpan(rectangle5, 2);
  98.             Grid.SetRow(rectangle5, 0);
  99.             Grid.SetColumn(rectangle5, 4);
  100.             visual.Children.Add(rectangle1);
  101.             visual.Children.Add(rectangle2);
  102.             visual.Children.Add(rectangle3);
  103.             visual.Children.Add(rectangle4);
  104.             visual.Children.Add(rectangle5);
  105.             return new VisualBrush(visual);
  106.         }
  107.  
  108.         public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
  109.         {
  110.             return new object[] { Binding.DoNothing };
  111.         }
  112.     }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement