private static void OrientationChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { int oldRowSpan = TileGrid.GetRowSpan(sender); int oldColSpan = TileGrid.GetColumnSpan(sender); TileGrid.SetColumnSpan(sender, oldRowSpan); TileGrid.SetRowSpan(sender, oldColSpan); HorizontalAlignment oldHAlign = (sender as NumberSlider).s.HorizontalAlignment; VerticalAlignment oldVAlign = (sender as NumberSlider).s.VerticalAlignment; (sender as NumberSlider).s.HorizontalAlignment = oldHAlign == HorizontalAlignment.Center ? HorizontalAlignment.Stretch : HorizontalAlignment.Center; (sender as NumberSlider).s.VerticalAlignment = oldVAlign == VerticalAlignment.Center ? VerticalAlignment.Stretch : VerticalAlignment.Center; }
private void PopulateControlPreviewWrapPanel(WrapPanel wp, IEnumerable <Type> controlTypes) { wp.Children.Clear(); foreach (Type controlType in controlTypes) { //do some fancy arranging. what we need: //size-to-fit border (plus some extra space) with transparent background to register the hits. //label the extra space with the name of the control SourcedControl c = (SourcedControl)controlType.GetConstructor(Type.EmptyTypes).Invoke(null); c.IsEnabled = false; double expectedWidth = TileGrid.GetColumnSpan(c) * 50; double expectedHeight = TileGrid.GetRowSpan(c) * 50; TileGrid container = new TileGrid() { ShowGridlines = false, IsEditable = false, TileSizingMode = TileSizingMode.Uniform, Width = expectedWidth, Height = expectedHeight, Background = new SolidColorBrush(Colors.Transparent) }; container.Children.Add(c); Border outline = new Border() { Background = new SolidColorBrush(Colors.Transparent), BorderBrush = new SolidColorBrush(Colors.Black), BorderThickness = new Thickness(1), Margin = new Thickness(5) }; StackPanel p = new StackPanel(); outline.Child = p; TextBlock label = new TextBlock() { Text = Util.ToTitleCase(controlType.Name), Margin = new Thickness(2) }; p.Children.Add(label); p.Children.Add(new Separator()); p.Children.Add(container); wp.Children.Add(outline); } }
private void PlaceAtDropPoint(SourcedControl c, DragEventArgs e) { Point dropPoint = e.GetPosition(dashboardRoot); //centering. goal: if there span is even, we want to center on nearest line, //if span is odd, center the nearest full tile //for even, rounding works because the division causes the control to tend towards the left int colSpan = TileGrid.GetColumnSpan(c); int rowSpan = TileGrid.GetRowSpan(c); double preciseCol = dropPoint.X / dashboardRoot.GetColumnWidth(); double preciseRow = dropPoint.Y / dashboardRoot.GetRowHeight(); int col = colSpan % 2 == 0 ? (int)Math.Round(preciseCol) : (int)Math.Floor(preciseCol); int row = rowSpan % 2 == 0 ? (int)Math.Round(preciseRow) : (int)Math.Floor(preciseRow); int colOffset = colSpan / 2; int rowOffset = rowSpan / 2; col = Math.Max(col - colOffset, 0); row = Math.Max(row - rowOffset, 0); TileGrid.SetColumn(c, col); TileGrid.SetRow(c, row); }