xaml VisualState 设置 Grid.Row/Column 元素

xaml VisualState set Grid.Row/Column of element

我有一个网格布局,其中一行有 7 个元素。如果 windowScreenWidth 小于 X,我想将最后 4 个元素从第一行移动到第二行。我已经添加了一个组和状态。 如果我使用 <Setter Target="el4.Grid.Row" Value="1"/><Setter Target="el4" Property="Grid.Row" Value="1"/> xaml 抛出异常。

有什么方法可以做出我想要的东西吗?

找到一些解决方法:

void WindowSizeChanged(object sender, SizeChangedEventArgs e)
{
  double width = e.NewSize.Width;
  if(width < 641)
  {
    el4.SetValue(Grid.RowProperty, 1);
    el4.SetValue(Grid.ColumnProperty, 0);
  }
  else
  {
    el4.SetValue(Grid.RowProperty, 0);
    el4.SetValue(Grid.ColumnProperty, 3);
  }
}

public MainPage()
{
  SizeChanged += WindowSizeChanged;
  this.InitializeComponent();
}

正确的XAML代码是:Target="el4.(Grid.Row)" Value="1"/>

有点晚了,但可能会对其他人有所帮助。因为给出的解决方案不是最好的(使用 if 而不是样式和状态)。