locked
How to add a static element on a GridView? RRS feed

  • Question

  • As you can see the images above, the GridView has already the feeds or items, but these ones contains static items.

    In this image, the item which I'm interest is 'See More'. I want to implement something like that in my application.

    In this another app, contains two static items:

    • All starts
    • Top free.

    Not, the question is, how can I add this item in the GridView? and when pressed.. execute something (like a button or command).

    In the meantime, I'm still practicing using Grid template from Metro App (if you want to post a project)

    Thanks in advance.

    Wednesday, June 13, 2012 10:51 PM

Answers

  • You could have the seemore item in your internal list that is displayed in the grid view, and use a data template selector to select the data template given the seemore item. e.g:

    class SeeMore: MyTypeOfListItemBase{

    }

    public class GridTemplateSelector : DataTemplateSelector
    {
        public DataTemplate NormalItem { get; set; }
        public DataTemplate SeeMoreTemplate { get; set; }
        protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
        {
            if (item is NormalItem)
            {
                return NormalTemplate;
            }
            if (item is SeeMore)
            {
                return SeeMoreTemplate;
            }
        }
    }

    in your page resources in the xaml file:

    <pages:GridTemplateSelector x:Key="ItemSelector" SeeMoreTemplate="{StaticResource SeeMoreTemplate}" NormalTemplate="{StaticResource NormalTemplate}"/>

    And in your gridview:
    ItemTemplateSelector="{StaticResource ItemSelector}"

    ...Stefan

    Thursday, June 14, 2012 12:47 AM

All replies

  • You can edit template of the gridview and add your controls next to the itemspresenter
    Wednesday, June 13, 2012 11:23 PM
  • I see, I don't have so much experience customizing control's templates. Could you show me an example doing this (better if you post an example from Grid default template from VS)?

    Thursday, June 14, 2012 12:10 AM
  • You could have the seemore item in your internal list that is displayed in the grid view, and use a data template selector to select the data template given the seemore item. e.g:

    class SeeMore: MyTypeOfListItemBase{

    }

    public class GridTemplateSelector : DataTemplateSelector
    {
        public DataTemplate NormalItem { get; set; }
        public DataTemplate SeeMoreTemplate { get; set; }
        protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
        {
            if (item is NormalItem)
            {
                return NormalTemplate;
            }
            if (item is SeeMore)
            {
                return SeeMoreTemplate;
            }
        }
    }

    in your page resources in the xaml file:

    <pages:GridTemplateSelector x:Key="ItemSelector" SeeMoreTemplate="{StaticResource SeeMoreTemplate}" NormalTemplate="{StaticResource NormalTemplate}"/>

    And in your gridview:
    ItemTemplateSelector="{StaticResource ItemSelector}"

    ...Stefan

    Thursday, June 14, 2012 12:47 AM