你的位置:首页 > 操作系统

[操作系统]win8 app GridView点击子项布局变更

要触发点击必须设置IsItemClickEnabled="True"

要变更布局代码如下:

 

 private void gridView_ItemClick_1(object sender, ItemClickEventArgs e)
        {
            ColorModel model = (e.ClickedItem as ColorModel);//自定义的类
            model.ColSpan = 2;//占的格数
            model.RowSpan = 2;//占的格数
            (VisualTreeHelper.GetChild(((VisualTreeHelper.GetChild(gridView, 0) as Border).Child as ScrollViewer).Content as FrameworkElement, 1) as VariableSizedWrapGrid).Children[gridView.Items.IndexOf(e.ClickedItem)].SetValue(Windows.UI.Xaml.Controls.VariableSizedWrapGrid.ColumnSpanProperty, model.ColSpan);
            (VisualTreeHelper.GetChild(((VisualTreeHelper.GetChild(gridView, 0) as Border).Child as ScrollViewer).Content as FrameworkElement, 1) as VariableSizedWrapGrid).Children[gridView.Items.IndexOf(e.ClickedItem)].SetValue(Windows.UI.Xaml.Controls.VariableSizedWrapGrid.RowSpanProperty, model.RowSpan);
            (VisualTreeHelper.GetChild(((VisualTreeHelper.GetChild(gridView, 0) as Border).Child as ScrollViewer).Content as FrameworkElement, 1) as VariableSizedWrapGrid).InvalidateArrange();//重新布局
            (VisualTreeHelper.GetChild(((VisualTreeHelper.GetChild(gridView, 0) as Border).Child as ScrollViewer).Content as FrameworkElement, 1) as VariableSizedWrapGrid).InvalidateMeasure();//重新计算

}