2012-08-06 20 views
5

Windows 8 için bir uygulama metro geliştiriyorum. GridApp (xaml) projesini kullanıyorum, ancak her bölümde farklı grup stili kullanmak istiyorum. Ben grup stilini seçiciye bu sınıfı kullanmakIzgara görünümünde grup stilini seçin

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"); 

    } 
} 

ve 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}" /> 

ama stil grubu tek seferde değiştirir:

Benim kodudur.

+0

(http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/ MSDN'da konu/63a5d82c-1ad2-4e24-bfb4-122d5551c5f0 /) sorunuzu yanıtlıyor. –

+0

Ve soru nedir? – Denis

+0

Tam olarak aynı sorun var ve bu konudaki herkes http://social.msdn.microsoft.com/Forums/en-GB/winappswithcsharp/thread/5f12273f-e000-4c96-a4bc-6ccc18a104a0 – krisdyson

cevap

0

Lvsti'nin işaret ettiği gibi, GroupStyleSelector yalnızca düzeyindeki düzeyindeki stili değiştirebilir. Örneğin. tüm seviye 0 grupları aynı stile sahip olacak ancak tüm düzey 1 grupları farklı bir stile sahip olabilir. Şu anda farklı stillerle 0 seviyesinde iki farklı gruba sahip olmak mümkün değil. Aslında, aynı seviyedeki herhangi bir grup için geri verilen son stilin, bu seviyedeki tüm gruplara uygulandığı görülmektedir. Bu talihsiz ama mevcut tasarım bu.

Dev desteği, tasarım desteği ve yolda daha müthiş iyilik: Sen eğer bu [thread] görebilirsiniz http://bit.ly/winappsupport

+1

bekle, burada bir şeyleri açıkça eksik. seviye 0 grubundan daha fazla nasıl olurdu? Grupları ve onların öğelerini (GroupedItemsView şablonunda olduğu gibi) göstermek için kullanılan gruplandırılmış tabloyu görmüştüm. A) birden fazla seviyeye sahip olan ve b) bir groupstyleselector kullanan gruplandırılmış bir gridview örneğini gösterir misiniz? teşekkür ederim! – SelAromDotNet