The form has a Grid (which goes beyond the form) and a button.

Question: how can I move the Grid in the direction I need (for example, to the left) by a certain number in Margin each time I press a button?

Ie the button was pressed, the value was added to the Grid, for example 50 to margin left, I pressed it once more, the same number was added

  • create marginLeft property in VM , bind Margin to this property. create a team that will increase this property. - Gardes
  • I don’t understand how to do it private void right_Click(object sender, RoutedEventArgs e) { Thickness margin = Block_1.Margin; this.Block_1.BeginAnimation(FrameworkElement.MarginProperty, new ThicknessAnimation(new Thickness(margin.Left = 50), TimeSpan.FromSeconds(0.10))); } lot, here’s the button code: private void right_Click(object sender, RoutedEventArgs e) { Thickness margin = Block_1.Margin; this.Block_1.BeginAnimation(FrameworkElement.MarginProperty, new ThicknessAnimation(new Thickness(margin.Left = 50), TimeSpan.FromSeconds(0.10))); } private void right_Click(object sender, RoutedEventArgs e) { Thickness margin = Block_1.Margin; this.Block_1.BeginAnimation(FrameworkElement.MarginProperty, new ThicknessAnimation(new Thickness(margin.Left = 50), TimeSpan.FromSeconds(0.10))); } private void right_Click(object sender, RoutedEventArgs e) { Thickness margin = Block_1.Margin; this.Block_1.BeginAnimation(FrameworkElement.MarginProperty, new ThicknessAnimation(new Thickness(margin.Left = 50), TimeSpan.FromSeconds(0.10))); } but it does not work correctly and does not add a margin .. - Elizabeth

1 answer 1

 private void right_Click(object sender, RoutedEventArgs e) { Thickness margin = Block_1.Margin; margin.Left += 50; this.Block_1.BeginAnimation(FrameworkElement.MarginProperty, new ThicknessAnimation(margin, TimeSpan.FromSeconds(0.10))); } 
  • The code is appropriate, but moving is strange, instead of a specific position to the left, the element is shifted to the right down ( - Elizabeth
  • @ Elizabeth, updated. - Gardes
  • Thank you!! - Elizabeth
  • @ Elizabeth, Please! - Gardes