override template rowsorcolumns in code behind RRS feed

  • Question

  • I have a GridView sourced from ViewModel and all is well. But I am having fits trying to "bind" or "update" the MaximumRowsOrColumns from code behind when the size changed fires:

    <WrapGrid Loaded="WrapGrid_Loaded_Left" Orientation="Horizontal" MaximumRowsOrColumns="1"/>

    I can override on Loaded but that does not work with size change event. Any help would be appreciated. Thanks.


    Friday, December 13, 2013 5:15 PM

All replies

  • Hi,

    What specific scenario do you want to achieve?

    In WrapGrid, there is a SizeChanged event. Which Occurs when either the ActualHeight or the ActualWidth property changes value on a FrameworkElement.

    And the WrapGrid will perform the initial layout based on the Size of the first item. If you change the height of any other item, that won't alter its layout and the SizeChanged event would not fire.

    Best Wishes!

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Anne Jing Friday, December 20, 2013 6:01 AM
    • Unmarked as answer by Frank14303 Saturday, December 21, 2013 6:20 PM
    Monday, December 16, 2013 2:36 AM
  • Thanks Anne. I have three grids across the page: Left, Middle, and Right. Each has a wrap grid with an unknown number of items.

                <ColumnDefinition Width="1*" /> // left
                <ColumnDefinition Width="2*" /> // middle
                <ColumnDefinition Width="1*" /> // right

    The width (and height) changes with orientation. So in Portrait I get 2/4/2 items and Landscape 4/8/4 items in each column. The columns are nice and tight and the Scroll viewer is OK. Looks great. Now if I resize let's say 40% portrait, there is not room for 2 in left column so it has 1 with a lot of white space. If I resize to 60% you get 5 with a lot of white space. I do not want to recalculate grid width every time and thought if I could override  MaximumRowsOrColumns  I could avoid the whitespace. This way the number of columns would always be a whole number and then there would be not white space. Does that make sense? The only other way I can think to do it is change the size of the items by calculations which seems awkward as well. any ideas? Thanks.


    Saturday, December 21, 2013 6:45 PM