private void StyledGrid_IncreaseColSpace(object sender, RoutedEventArgs e) { ActualColSpace += 1; // Update text box with newly increased value ColSpace.Text = ActualColSpace.ToString(); ColSpace.PlaceholderText = ActualColSpace.ToString(); ColSpacesDec.IsEnabled = true; // Increase left/right margin on all GridViewItems for (int i = 0; i < StyledGrid.Items.Count; i++) { GridViewItem item = StyledGrid.ContainerFromIndex(i) as GridViewItem; // Create a Thickness property to bind to each item's Margin property. // Use existing margin and only change relevant values (left/right) Thickness NewMargin = item.Margin; NewMargin.Left = item.Margin.Left + 1; NewMargin.Right = item.Margin.Right + 1; item.Margin = NewMargin; } NotifyPropertyChanged(); }
private void NumberBox_ValueChanged(Microsoft.UI.Xaml.Controls.NumberBox sender, Microsoft.UI.Xaml.Controls.NumberBoxValueChangedEventArgs args) { if (StyledGridIWG == null) { return; } // Only update either max-row value or margins if (sender == WrapItemCount) { StyledGridIWG.MaximumRowsOrColumns = (int)WrapItemCount.Value; return; } int rowSpace = (int)RowSpace.Value; int columnSpace = (int)ColumnSpace.Value; for (int i = 0; i < StyledGrid.Items.Count; i++) { GridViewItem item = StyledGrid.ContainerFromIndex(i) as GridViewItem; Thickness NewMargin = item.Margin; NewMargin.Left = columnSpace; NewMargin.Top = rowSpace; NewMargin.Right = columnSpace; NewMargin.Bottom = rowSpace; item.Margin = NewMargin; } }
private void StyledGrid_ChangeCol(object sender, TextChangedEventArgs e) { try { // Make sure that value entered is a number int newVal = Convert.ToInt32(ColSpace.Text.ToString()); // If empty or negative string, reset to 0. if (ColSpace.Text.ToString() != "" && newVal >= 0) { ColSpacesDec.IsEnabled = true; ColSpace.Text = ColSpace.Text.ToString(); ColSpace.PlaceholderText = ColSpace.Text.ToString(); // Create new Thickness object and update relevant parts of Margin property (top/bottom) for (int i = 0; i < StyledGrid.Items.Count; i++) { GridViewItem item = StyledGrid.ContainerFromIndex(i) as GridViewItem; Thickness NewMargin = item.Margin; NewMargin.Left = Convert.ToInt32(ColSpace.Text); NewMargin.Right = Convert.ToInt32(ColSpace.Text); item.Margin = NewMargin; } } else { ColSpace.Text = ""; ColSpace.PlaceholderText = ""; } } // If entered value not a number, reset to 0. catch (FormatException) { // If clearing a text entry, reset margins to 0. if (ColSpace.Text == "") { for (int i = 0; i < StyledGrid.Items.Count; i++) { GridViewItem item = StyledGrid.ContainerFromIndex(i) as GridViewItem; Thickness NewMargin = item.Margin; NewMargin.Left = 0; NewMargin.Right = 0; item.Margin = NewMargin; } ColSpacesDec.IsEnabled = false; } ColSpace.Text = ""; ColSpace.PlaceholderText = "0"; } }
private void StyledGrid_DecreaseRowSpace(object sender, RoutedEventArgs e) { // Make sure new value is positive if (ActualRowSpace > 0) { ActualRowSpace -= 1; RowSpacesDec.IsEnabled = true; // Update text box with newly increased value RowSpace.Text = ActualRowSpace.ToString(); RowSpace.PlaceholderText = ActualRowSpace.ToString(); // Decrease top/bottom margin on all GridViewItems for (int i = 0; i < StyledGrid.Items.Count; i++) { GridViewItem item = StyledGrid.ContainerFromIndex(i) as GridViewItem; // Create a Thickness property to bind to each item's Margin property. // Use existing margin and only change relevant values (top/bottom) Thickness NewMargin = item.Margin; NewMargin.Top = item.Margin.Top - 1; NewMargin.Bottom = item.Margin.Bottom - 1; item.Margin = NewMargin; } // If this action caused RowSpaces to go to 0, deactivate decrease button if (ActualRowSpace == 0) { RowSpacesDec.IsEnabled = false; } } // If new value is negative, reset text box to 0 and display an error message. else { RowSpace.Text = ""; RowSpace.PlaceholderText = "0"; RowSpacesDec.IsEnabled = false; } NotifyPropertyChanged(); }
private void StyledGrid_IncreaseRowSpace(object sender, RoutedEventArgs e) { ActualRowSpace += 1; RowSpacesDec.IsEnabled = true; RowSpace.Text = ActualRowSpace.ToString(); RowSpace.PlaceholderText = ActualRowSpace.ToString(); // Increase top/bottom margin on all GridViewItems for (int i = 0; i < StyledGrid.Items.Count; i++) { GridViewItem item = StyledGrid.ContainerFromIndex(i) as GridViewItem; // Create a Thickness property to bind to each item's Margin property. // Use existing margin and only change relevant values (top/bottom) Thickness NewMargin = item.Margin; NewMargin.Top = item.Margin.Top + 1; NewMargin.Bottom = item.Margin.Bottom + 1; item.Margin = NewMargin; } NotifyPropertyChanged(); }