How can I access the ItemsWrapGrid defined in the GridView in C# RRS feed

  • Question

  • I have a GridView defined in XAML.  Here the GridView.ItemsPanel --> ItemsPanelTemplate --> ItemsWrapGrid has "MaximumRowsOrColumns" defined in XAML.

    If I need to change the MaximumRowsOrColumns value programmatically based on current page size, how can I access the ItemsWrapGrid object in C#?  "this.MyItemsWrapGrid" is not working.

                            <ItemsWrapGrid x:Name="MyItemsWrapGrid" MaximumRowsOrColumns="5"/>
    Tuesday, April 29, 2014 11:51 PM


  • In the code behind, have a private var ItemsWrapGrid which you set when Gridview is loaded. 


                        <ItemsWrapGrid Loaded="MyItemsWrapGrid_Loaded" x:Name="MyItemsWrapGrid"
                                       MaximumRowsOrColumns="5" />


            private ItemsWrapGrid _itemsWrapGrid;
            private void MyItemsWrapGrid_Loaded(object sender, RoutedEventArgs e)
                _itemsWrapGrid = sender as ItemsWrapGrid;

    • Edited by Bryan Stump Wednesday, April 30, 2014 12:51 AM
    • Marked as answer by LChen_MSDN Wednesday, April 30, 2014 8:19 PM
    Wednesday, April 30, 2014 12:51 AM