2012-08-06 4 views
5

윈도우 8 용 앱 메트로를 개발 중입니다. GridApp (xaml) 프로젝트를 사용하지만 각 섹션마다 다른 그룹 스타일을 사용하고 싶습니다. I 그룹 스타일을 선택하기 위해이 클래스를 사용그리드 뷰에서 그룹 스타일 선택

public class GroupTemplateSelector : GroupStyleSelector 
{ 

    public GroupStyle NewsItemGroupStyle { get; set; } 
    public GroupStyle NormalGroupStyle { get; set; } 

    protected override GroupStyle SelectGroupStyleCore(object group, uint level) 
    { 
     // a method that tries to grab an enum off the bound data object 

     if (level == 3) 
     { 
      return NewsItemGroupStyle; 
     } 
     else 
     { 
      return NormalGroupStyle; 
     } 

     throw new ArgumentException("Unexpected group type"); 

    } 
} 

및 XAML

<!-- NewsItemGroupStyle --> 
<GroupStyle x:Key="NewsItemGroupStyle"> 
    <GroupStyle.HeaderTemplate> 
     <DataTemplate> 
     </DataTemplate> 
    </GroupStyle.HeaderTemplate> 
    <GroupStyle.Panel> 
     <ItemsPanelTemplate> 
      <StackPanel Orientation="Vertical" Margin="0,0,80,0" VerticalAlignment="Bottom"/> 
     </ItemsPanelTemplate> 
    </GroupStyle.Panel> 
</GroupStyle> 


<!-- NormalItemGroupStyle --> 
<GroupStyle x:Key="NormalGroupStyle"> 
    <GroupStyle.HeaderTemplate> 
     <DataTemplate> 
      <Grid Margin="1,0,0,6"> 
       <Button 
        AutomationProperties.Name="Group Title" 
        Content="{Binding Title}" 
        Background="Blue" 
        Click="Header_Click" 
        Style="{StaticResource TextButtonStyle}" 
        /> 
      </Grid> 
     </DataTemplate> 
    </GroupStyle.HeaderTemplate> 
    <GroupStyle.Panel> 
     <ItemsPanelTemplate> 
      <VariableSizedWrapGrid Orientation="Vertical" Margin="0,0,80,0"/> 
     </ItemsPanelTemplate> 
    </GroupStyle.Panel> 
</GroupStyle> 

<!-- selector --> 
<common:GroupTemplateSelector 
    x:Key="groupSelector" 
    NewsItemGroupStyle="{StaticResource NewsItemGroupStyle}" 
    NormalGroupStyle="{StaticResource NormalGroupStyle}" /> 

하지만 스타일의 그룹은 한 번에 변경 :

내 코드입니다.

+0

(http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/ thread/63a5d82c-1ad2-4e24-bfb4-122d5551c5f0 /)를 사용하여 질문에 대한 답변을 얻을 수 있습니다. –

+0

그리고 질문은 무엇입니까? – Denis

+0

나는 정확히 같은 문제가 있고이 스레드의 모든 사람들도 마찬가지입니다. http://social.msdn.microsoft.com/Forums/en-GB/winappswithcsharp/thread/5f12273f-e000-4c96-a4bc-6ccc18a104a0 – krisdyson

답변

0

Lvsti가 지적했듯이 GroupStyleSelector는 각 레벨에서만 스타일을 변경할 수 있습니다. 예 : 모든 레벨 0 그룹은 동일한 스타일을 갖지만 모든 레벨 1 그룹은 다른 스타일을 가질 수 있습니다. 현재 레벨 0에서 서로 다른 스타일로 두 개의 다른 그룹을 가질 수 없습니다. 실제로 동일한 레벨의 그룹에 대해 반환 된 마지막 스타일은 해당 레벨의 모든 그룹에 적용됩니다. 그것은 불행한 일이지만, 그것이 현재의 디자인입니다.

데브 지원, 설계 지원 및 방법에 대한 자세한 멋진 선 (善) 다음과 같은 경우이 [스레드]을 볼 수 있습니다 http://bit.ly/winappsupport

+1

기다려라, 나는 분명히 여기에서 무엇인가 놓치고있다. 레벨 0 그룹 이상은 어떻습니까? GroupedItemsView 템플릿과 같이 그룹 및 항목을 표시하는 데 사용되는 그룹화 된 gridview 만 보았습니다. a) 둘 이상의 레벨이 있고 b) groupstylesclector를 사용하는 그룹화 된 gridview의 예를 보여줄 수 있습니까? 고맙습니다! – SelAromDotNet