2012-07-10 6 views
12

Windows 8 Metro 앱을 쓰고 있습니다. 나는 3 개의 그룹으로 GridView를 그리려고한다. 나는 그 그룹 중 하나가 자신의 아이템을 다른 것들과 다르게 배치하기를 원한다. 전에 WPF에서 Selectors를 사용 했으므로 좋은 경로라고 생각했습니다. 그래서 GroupStyleSelector을 시도하고 나는이 example on MSDN 발견메트로 GridView에서 그룹을 다른 레이아웃으로 사용하려면 어떻게해야합니까?

CS를 :

public class ListGroupStyleSelector : GroupStyleSelector 
{ 
    protected override GroupStyle SelectGroupStyleCore(object group, uint level) 
    { 
    return (GroupStyle)App.Current.Resources["listViewGroupStyle"]; 
    } 
} 

그래서 나는 나에게 맞는 것 무언가에서의 확장/변경

public class ExampleListGroupStyleSelector : GroupStyleSelector 
{ 
    public ExampleListGroupStyleSelector() 
    { 
    OneBigItemGroupStyle = null; 
    NormalGroupStyle = null; 
    } 

    public GroupStyle OneBigItemGroupStyle { 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 
    var exampleListType= GetExampleListType(group); 

    if (exampleListType== ExampleListType.A) 
    { 
     return OneBigItemGroupStyle; 
    } 
    if (exampleListType== ExampleListType.B|| exampleListType== ExampleListType.B) 
    { 
     return NormalGroupStyle; 
    } 

    throw new ArgumentException("Unexpected group type"); 
    } 
} 

XAML :

<Page.Resources> 
    <ExampleListGroupStyleSelector 
    x:Key="ExampleListGroupStyleSelector" 
    OneBigItemGroupStyle="{StaticResource OneBigGroupStyle}" 
    NormalGroupStyle="{StaticResource NormalGroupStyle}" /> 
</Page.Resources> 
<GridView 
    ItemsSource="{Binding Source={StaticResource exampleListsViewSource}}" 
    GroupStyleSelector="{StaticResource ExampleListGroupStyleSelector}"> 
    <GridView.ItemsPanel> 
     <ItemsPanelTemplate> 
      <VirtualizingStackPanel 
       Orientation="Horizontal" /> 
     </ItemsPanelTemplate> 
    </GridView.ItemsPanel> 
</GridView> 

하지만 선택기에서 주어진 그룹은 null이거나 DependencyObject tha입니다. 나는 어떤 데이터도 꺼낼 수 없다. 어떤 정보도 제공받지 못하면 GroupStyle을 변경하는 방법에 대해 어떻게 지혜로운 결정을 내릴 수 있습니까? 첨부 된 속성이나 그 선을 따라 뭔가를 통해 속성을 전달할 수있는 방법이 있습니까?

답변

1

이 포럼 thread에 기반하여 개체를 ICollectionView로 캐스팅하고 그룹에 바인딩 한 개체를 가져올 .Group 속성에 액세스하여 개체를 추출 할 수 있습니다. 이를 통해 템플릿에 대한 지능적인 결정이 가능합니다. 그러나 다른 스타일이 반환된다는 사실에도 불구하고 하나의 스타일 만 적용되므로 나 (또는 ​​스레드의 다른 사람들)에게는 여전히 작동하지 않습니다.

편집 : GroupTemplate은 다른 그룹을 생성하기위한 것이 아닙니다. 예를 들어 스냅 된보기 또는 모든 그룹이 변경되는 유사한 경우에서 그룹의보기를 변경하기위한 것입니다.

관련 문제