private static void SetSquareModeBinding(FrameworkElement element, SquareMode squareMode) { if (element == null) { throw new ArgumentNullException("element"); } //http://blog.wpfwonderland.com/2010/10/04/sizeable-yet-square-content-control/ System.Windows.Data.Binding Binding; switch (squareMode) { case SquareMode.WidthMatchesActualHeight: //Force the element's width to match its actual height. Binding = new System.Windows.Data.Binding(); Binding.Path = new PropertyPath(FrameworkElement.ActualHeightProperty.Name); Binding.RelativeSource = new System.Windows.Data.RelativeSource(System.Windows.Data.RelativeSourceMode.Self); element.SetBinding(FrameworkElement.WidthProperty, Binding); break; case SquareMode.HeightMatchesActualWidth: //Force the element's height to match its actual width. Binding = new System.Windows.Data.Binding(); Binding.Path = new PropertyPath(FrameworkElement.ActualWidthProperty.Name); Binding.RelativeSource = new System.Windows.Data.RelativeSource(System.Windows.Data.RelativeSourceMode.Self); element.SetBinding(FrameworkElement.HeightProperty, Binding); break; } }
private static Color GetSquareColor(Square square, SquareMode squareMode) { var squareColors = SquareColorMap[squareMode]; var isDarkSquare = square.IsDark(); return(squareColors[isDarkSquare]); }
private static void ClearSquareModeBinding(FrameworkElement element, SquareMode squareMode) { if (element == null) { throw new ArgumentNullException("element"); } switch (squareMode) { case SquareMode.WidthMatchesActualHeight: System.Windows.Data.BindingOperations.ClearBinding(element, FrameworkElement.WidthProperty); break; case SquareMode.HeightMatchesActualWidth: System.Windows.Data.BindingOperations.ClearBinding(element, FrameworkElement.HeightProperty); break; } }
public static Brush GetSquareBrush(Square square, SquareMode squareMode) { var color = GetSquareColor(square, squareMode); return(new SolidColorBrush(color)); }
public static void SetSquareMode(FrameworkElement o, SquareMode Value) { o.SetValue(SquareModeProperty, Value); }
private static void SetSquareModeBinding(FrameworkElement element, SquareMode squareMode) { if (element == null) throw new ArgumentNullException("element"); //http://blog.wpfwonderland.com/2010/10/04/sizeable-yet-square-content-control/ System.Windows.Data.Binding Binding; switch (squareMode) { case SquareMode.WidthMatchesActualHeight: //Force the element's width to match its actual height. Binding = new System.Windows.Data.Binding(); Binding.Path = new PropertyPath(FrameworkElement.ActualHeightProperty.Name); Binding.RelativeSource = new System.Windows.Data.RelativeSource(System.Windows.Data.RelativeSourceMode.Self); element.SetBinding(FrameworkElement.WidthProperty, Binding); break; case SquareMode.HeightMatchesActualWidth: //Force the element's height to match its actual width. Binding = new System.Windows.Data.Binding(); Binding.Path = new PropertyPath(FrameworkElement.ActualWidthProperty.Name); Binding.RelativeSource = new System.Windows.Data.RelativeSource(System.Windows.Data.RelativeSourceMode.Self); element.SetBinding(FrameworkElement.HeightProperty, Binding); break; } }
private static void ClearSquareModeBinding(FrameworkElement element, SquareMode squareMode) { if (element == null) throw new ArgumentNullException("element"); switch (squareMode) { case SquareMode.WidthMatchesActualHeight: System.Windows.Data.BindingOperations.ClearBinding(element, FrameworkElement.WidthProperty); break; case SquareMode.HeightMatchesActualWidth: System.Windows.Data.BindingOperations.ClearBinding(element, FrameworkElement.HeightProperty); break; } }
public static void SetSquareMode(FrameworkElement o, SquareMode Value) { o.SetValue(SquareModeProperty, Value); }