123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- using System.Windows.Shapes;
- namespace MECF.Framework.UI.Core.Style
- {
- public class GridHelper
- {
- public static Brush GetColumn0(DependencyObject obj)
- {
- return (Brush)obj.GetValue(Column0Property);
- }
- public static void SetColumn0(DependencyObject obj, Brush value)
- {
- obj.SetValue(Column0Property, value);
- }
- // Using a DependencyProperty as the backing store for Column0. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty Column0Property =
- DependencyProperty.RegisterAttached("Column0", typeof(Brush), typeof(GridHelper), new FrameworkPropertyMetadata(null, PropertyChangedCallback));
- public static Brush GetColumn1(DependencyObject obj)
- {
- return (Brush)obj.GetValue(Column1Property);
- }
- public static void SetColumn1(DependencyObject obj, Brush value)
- {
- obj.SetValue(Column1Property, value);
- }
- // Using a DependencyProperty as the backing store for Column1. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty Column1Property =
- DependencyProperty.RegisterAttached("Column1", typeof(Brush), typeof(GridHelper), new FrameworkPropertyMetadata(null, PropertyChangedCallback));
- public static Brush GetColumn2(DependencyObject obj)
- {
- return (Brush)obj.GetValue(Column2Property);
- }
- public static void SetColumn2(DependencyObject obj, Brush value)
- {
- obj.SetValue(Column2Property, value);
- }
- // Using a DependencyProperty as the backing store for Column2. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty Column2Property =
- DependencyProperty.RegisterAttached("Column2", typeof(Brush), typeof(GridHelper), new FrameworkPropertyMetadata(null, PropertyChangedCallback));
- public static Brush GetColumn3(DependencyObject obj)
- {
- return (Brush)obj.GetValue(Column3Property);
- }
- public static void SetColumn3(DependencyObject obj, Brush value)
- {
- obj.SetValue(Column3Property, value);
- }
- // Using a DependencyProperty as the backing store for Column3. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty Column3Property =
- DependencyProperty.RegisterAttached("Column3", typeof(Brush), typeof(GridHelper), new FrameworkPropertyMetadata(null, PropertyChangedCallback));
- public static Brush GetStroke(DependencyObject obj)
- {
- return (Brush)obj.GetValue(StrokeProperty);
- }
- public static void SetStroke(DependencyObject obj, Brush value)
- {
- obj.SetValue(StrokeProperty, value);
- }
- // Using a DependencyProperty as the backing store for Stroke. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty StrokeProperty =
- DependencyProperty.RegisterAttached("Stroke", typeof(Brush), typeof(GridHelper), new PropertyMetadata(Brushes.White));
- public static Brush GetColumn4(DependencyObject obj)
- {
- return (Brush)obj.GetValue(Column4Property);
- }
- public static void SetColumn4(DependencyObject obj, Brush value)
- {
- obj.SetValue(Column4Property, value);
- }
- // Using a DependencyProperty as the backing store for Column4. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty Column4Property =
- DependencyProperty.RegisterAttached("Column4", typeof(Brush), typeof(GridHelper), new PropertyMetadata(null, PropertyChangedCallback));
- public static Brush GetColumn5(DependencyObject obj)
- {
- return (Brush)obj.GetValue(Column5Property);
- }
- public static void SetColumn5(DependencyObject obj, Brush value)
- {
- obj.SetValue(Column5Property, value);
- }
- // Using a DependencyProperty as the backing store for Column5. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty Column5Property =
- DependencyProperty.RegisterAttached("Column5", typeof(Brush), typeof(GridHelper), new PropertyMetadata(null, PropertyChangedCallback));
- public static Brush GetColumn6(DependencyObject obj)
- {
- return (Brush)obj.GetValue(Column6Property);
- }
- public static void SetColumn6(DependencyObject obj, Brush value)
- {
- obj.SetValue(Column6Property, value);
- }
- // Using a DependencyProperty as the backing store for Column6. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty Column6Property =
- DependencyProperty.RegisterAttached("Column6", typeof(Brush), typeof(GridHelper), new PropertyMetadata(null, PropertyChangedCallback));
- public static Brush GetColumn7(DependencyObject obj)
- {
- return (Brush)obj.GetValue(Column7Property);
- }
- public static void SetColumn7(DependencyObject obj, Brush value)
- {
- obj.SetValue(Column7Property, value);
- }
- // Using a DependencyProperty as the backing store for Column7. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty Column7Property =
- DependencyProperty.RegisterAttached("Column7", typeof(Brush), typeof(GridHelper), new PropertyMetadata(null, PropertyChangedCallback));
- public static Brush GetColumn8(DependencyObject obj)
- {
- return (Brush)obj.GetValue(Column8Property);
- }
- public static void SetColumn8(DependencyObject obj, Brush value)
- {
- obj.SetValue(Column8Property, value);
- }
- // Using a DependencyProperty as the backing store for Column8. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty Column8Property =
- DependencyProperty.RegisterAttached("Column8", typeof(Brush), typeof(GridHelper), new PropertyMetadata(null, PropertyChangedCallback));
- public static Brush GetColumn9(DependencyObject obj)
- {
- return (Brush)obj.GetValue(Column9Property);
- }
- public static void SetColumn9(DependencyObject obj, Brush value)
- {
- obj.SetValue(Column9Property, value);
- }
- // Using a DependencyProperty as the backing store for Column9. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty Column9Property =
- DependencyProperty.RegisterAttached("Column9", typeof(Brush), typeof(GridHelper), new PropertyMetadata(null, PropertyChangedCallback));
- public static Brush GetColumn10(DependencyObject obj)
- {
- return (Brush)obj.GetValue(Column10Property);
- }
- public static void SetColumn10(DependencyObject obj, Brush value)
- {
- obj.SetValue(Column10Property, value);
- }
- // Using a DependencyProperty as the backing store for Column10. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty Column10Property =
- DependencyProperty.RegisterAttached("Column10", typeof(Brush), typeof(GridHelper), new PropertyMetadata(null, PropertyChangedCallback));
- public static Brush GetColumn11(DependencyObject obj)
- {
- return (Brush)obj.GetValue(Column11Property);
- }
- public static void SetColumn11(DependencyObject obj, Brush value)
- {
- obj.SetValue(Column11Property, value);
- }
- // Using a DependencyProperty as the backing store for Column11. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty Column11Property =
- DependencyProperty.RegisterAttached("Column11", typeof(Brush), typeof(GridHelper), new PropertyMetadata(null, PropertyChangedCallback));
- public static Brush GetColumn12(DependencyObject obj)
- {
- return (Brush)obj.GetValue(Column12Property);
- }
- public static void SetColumn12(DependencyObject obj, Brush value)
- {
- obj.SetValue(Column12Property, value);
- }
- // Using a DependencyProperty as the backing store for Column12. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty Column12Property =
- DependencyProperty.RegisterAttached("Column12", typeof(Brush), typeof(GridHelper), new PropertyMetadata(null, PropertyChangedCallback));
- public static Brush GetColumn13(DependencyObject obj)
- {
- return (Brush)obj.GetValue(Column13Property);
- }
- public static void SetColumn13(DependencyObject obj, Brush value)
- {
- obj.SetValue(Column13Property, value);
- }
- // Using a DependencyProperty as the backing store for Column13. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty Column13Property =
- DependencyProperty.RegisterAttached("Column13", typeof(Brush), typeof(GridHelper), new PropertyMetadata(null, PropertyChangedCallback));
- public static Brush GetColumn14(DependencyObject obj)
- {
- return (Brush)obj.GetValue(Column14Property);
- }
- public static void SetColumn14(DependencyObject obj, Brush value)
- {
- obj.SetValue(Column14Property, value);
- }
- // Using a DependencyProperty as the backing store for Column14. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty Column14Property =
- DependencyProperty.RegisterAttached("Column14", typeof(Brush), typeof(GridHelper), new PropertyMetadata(null, PropertyChangedCallback));
- public static Brush GetColumn15(DependencyObject obj)
- {
- return (Brush)obj.GetValue(Column15Property);
- }
- public static void SetColumn15(DependencyObject obj, Brush value)
- {
- obj.SetValue(Column15Property, value);
- }
- // Using a DependencyProperty as the backing store for Column15. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty Column15Property =
- DependencyProperty.RegisterAttached("Column15", typeof(Brush), typeof(GridHelper), new PropertyMetadata(null, PropertyChangedCallback));
- private static void PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- var grid = d as Grid;
- if (grid != null)
- {
- var col = int.Parse(e.Property.Name.Substring("Column".Length));
- RoutedEventHandler setup = null;
- setup = (s, x) =>
- {
- grid.Loaded -= setup;
- var count = VisualTreeHelper.GetChildrenCount(grid);
- for (int i = 0; i < count; i++)
- {
- var control = grid.Children[i];
- var columnSpan = Grid.GetColumnSpan(control);
- if (columnSpan > 1)
- {
- continue;
- }
- var column = Grid.GetColumn(control);
- if (col == column)
- {
- if (control is Label && e.NewValue == Brushes.Transparent)
- {
- //((Label)control).Style = (System.Windows.Style)Application.Current.TryFindResource("MiddleCenterLabel");
- }
- var rect = new Rectangle();
- rect.StrokeThickness = 1;
- rect.Stroke = GetStroke(grid);
- rect.Fill = e.NewValue as Brush;
- var row = Grid.GetRow(control);
- Grid.SetRow(rect, row);
- Grid.SetColumn(rect, col);
- grid.Children.Insert(i, rect);
- i++;
- count++;
- }
- }
- };
- grid.Loaded += setup;
- }
- }
- }
- }
|