locked
How to use GroupStyleSelectorCore to change the GroupStyle?

    Question

  • I find this question in C# forum, but I didn't find the answer.

    My question is I want to select different GroupStyle for a grouped GridView control. When I derive a class from GroupStyleSelector and override virtual method SelectGroupStyleCore(), I only can return a default GroupStyle. My code looks like this:

    public ref class myGroupStyleSelector sealed : public Windows::UI::Xaml::Controls::GroupStyleSelector
    	{
    	public:
    		property Windows::UI::Xaml::Controls::GroupStyle^ groupTemplate0;
    		property Windows::UI::Xaml::Controls::GroupStyle^ groupTemplate1;
    		property Windows::UI::Xaml::Controls::GroupStyle^ groupTemplate2;
    
    				virtual Windows::UI::Xaml::Controls::GroupStyle^ SelectGroupStyleCore(Platform::Object^ group, unsigned int level) override
    		{
    			
    			auto collectionViewGroup = safe_cast<Windows::UI::Xaml::Data::ICollectionViewGroup^>(group);
    			if(collectionViewGroup != nullptr)
    			{
    //ItemsContainer include Items
    				auto groupVM = safe_cast<ItemsContainer^>(collectionViewGroup->Group);
    				if(groupVM != nullptr)
    				{
    // ContainerGroup is a Groups enum, indicate which group is
    					switch(groupVM->ContainerGroup)
    					{
    						case Groups::Group1:
    							return groupTemplate0;
    							break;
    						case Groups::Group2:
    							return groupTemplate1;
    							break;
    						default:
    							return groupTemplate2;
    							break;
    					}
    				}
    				return Windows::UI::Xaml::Controls::GroupStyleSelector::SelectGroupStyleCore(group, level);
    			}
    // If I write it like this, I always get groupTemplate1, why?
    			return groupTemplate1;
    		}
    	};

    I set a break point at beginning of this class, and I notify when the first and second time this method was invoked, the group and level is 0, at the third time level is 1, but I only get goupTemplate1. Is that I forgot something?

    Thanks!

    Tuesday, August 28, 2012 1:33 PM

All replies