locked
Resize items in gridview dynamically

    Question

  • I have a gridview which displays items at a particular size using a DataTemplate. I want to be able to reduce the size of all the items by tapping on a button at runtime.

    I have seen lots of examples of using a template selector but they all use a property of the item such as isSelected, so when you select an item the template selector changes that item but I cant find anything to do all the items from outside the grid.

    Anyone know how I can achieve this?


    Mal

    Wednesday, April 30, 2014 4:58 PM

Answers

  • If you want to swap out all items you can just switch the ItemTemplate for the new DataTemplate and all should work.

    You would only need a TemplateSelector if you want to different items to have different templates at the same time.

    --Rob

    • Marked as answer by MalBall Wednesday, April 30, 2014 10:04 PM
    Wednesday, April 30, 2014 8:33 PM
    Owner

All replies

  • What do you mean by reducing the size? Do you want to reduce the size of the whole grid? Or of specific items within the grid? Can you post a quick sketch of what you want?

    Typically you'd changes sizes by applying a scaling RenderTransform. The TemplateSelector would be more to change the control layout within specific items. As you say, the TemplateSelector is based on the item's properties, but you could have it combine those with outside influences.

    --Rob

    Wednesday, April 30, 2014 5:28 PM
    Owner
  • Its to change the displayed items within the grid. At the default size I display a picture, Title, date and rating but at smaller sizes I need to remove some of these and just show the picture and maybe the title.

    Mal

    Wednesday, April 30, 2014 5:45 PM
  • If you want to swap out all items you can just switch the ItemTemplate for the new DataTemplate and all should work.

    You would only need a TemplateSelector if you want to different items to have different templates at the same time.

    --Rob

    • Marked as answer by MalBall Wednesday, April 30, 2014 10:04 PM
    Wednesday, April 30, 2014 8:33 PM
    Owner
  • Thanks Rob that's don't the trick

    Mal

    Wednesday, April 30, 2014 10:04 PM