2016-07-24 8 views
0

私は数日間この問題に悩まされています。解決策は決して見つかりませんでした。だから私はCountryと呼ばれる項目のリストを持っています。このリストにはLeagueという項目の別のリストもあります。私は、国民の名とリーグ名にこのすべてを整理するためにCollectionViewSourceを作成しましたが、私はすべてのリーグ名バインドすることはできません。CollectionViewSourceのアイテムのリストをバインドする方法は?

<CollectionViewSource Source="{Binding Country}" x:Key="GroupedItems"> 
      <CollectionViewSource.GroupDescriptions> 
       <PropertyGroupDescription PropertyName="Name" /> 
       <PropertyGroupDescription PropertyName="League.Name" /> 
      </CollectionViewSource.GroupDescriptions> 
</CollectionViewSource> 

を私が書く必要があります:<PropertyGroupDescription PropertyName="League[0].Name" />

をが、これはのみ結合しますリーグリストの最初の項目。どんな解決策ですか?

実践例はイタリアの国は2つのリーグ(セリエAとセリエB)を持っており、イングランド(プレミアリーグ)が、2カ国(イタリア、イングランド)があるとします。 セリエAとセリエBは、合計3試合、セリエAで2セリエBで1を含む。プレミアリーグでは4試合がある。 you can see hereは、UIでこの構造体を表示しなければならないというのが私の他のトピックとしてリストビュー組織では :

ITALY 
    SERIE A 
      INTER 
      MILAN 
    SERIE B 
      JUVENTUS 
ENGLAND 
    PREMIERE LEAGUE 
      LEICESTER 
      MANCHESTER UNITED 
      MANCHESTER CITY 
      LIVERPOOL 
今イタリアとイングランドエキスパンダーでセリエA、セリエBとプレミアリーグ、などgroupstyleに配置されている

(私の他の質問で分かるように)各リーグの試合があります。

Nations->Leagues->Matches 
+0

(1)それはあなたの意図が何であるかは明らかではありません。 「リーグ」がコレクションの場合、「リーグ。名前」は何を返すべきか? (2) 'CollectionViewSource'は' Binding'のようなプロパティパスを使用しないので、プロパティ名のみを指定できます。 (3)このコレクションにバインドしているものを表示する必要があります。 2つのリスト(マスターディテール)ですか?ツリービュー? –

+0

より多くのcsコードを投稿してください。あなたが望むものを正確に入手してください。 –

+0

@EliArbel私はより完全なシナリオをここに掲載しました:http://stackoverflow.com/questions/38549818/cannot-bind-list-of-items-in-gridview-column残念ながら誰も答えていません – Heisenberg

答えて

1

: 問題がCollectionViewSourceに、私は「リーグがリスト内にある原因リーグの名前を表示することができないということですが、同じ問題が試合のためである、それはリーグ戦で使用可能なリスト、データ構造であり、私はあなたが望む出力を行った。これがあなたが望むものかどうかを確認して教えてください。

public partial class WinExpander : Window 
{ 
    public WinExpander() 
    { 
     InitializeComponent(); 

     this.DataContext = new ViewModel(); 
    } 
} 

public class ViewModel 
    { 
     public List<Country> Countries { get; set; } 
     public ViewModel() 
     { 
      Countries = new List<Country>(); 
     } 
    } 

public class Country 
    { 
     public string Name { get; set; } 
     public List<League> Leagues { get; set; } 

     public Country() 
     { 
      Leagues = new List<League>(); 
     } 
    } 

    public class League 
    { 
     public string Name { get; set; } 
     public List<Match> Matches { get; set; } 

     public League() 
     { 
      Matches = new List<Match>(); 
     } 
    } 

    public class Match 
    { 
     public string Name { get; set; } 
    } 

XAML

<Window.Resources> 
    <CollectionViewSource x:Key="GroupedItems" Source="{Binding Countries}"/> 
</Window.Resources> 
... 
<ItemsControl ItemsSource="{Binding Source={StaticResource GroupedItems}}"> 
      <ItemsControl.ItemTemplate> 
       <DataTemplate> 
        <Expander Header="{Binding Name}"> 
         <ItemsControl ItemsSource="{Binding Leagues}" Margin="25 0 0 0"> 
          <ItemsControl.ItemTemplate> 
           <DataTemplate> 
            <Expander Header="{Binding Name}"> 
             <ItemsControl ItemsSource="{Binding Matches}" Margin="25 0 0 0"> 
              <ItemsControl.ItemTemplate> 
               <DataTemplate> 
                <TextBlock Text="{Binding Name}"/> 
               </DataTemplate> 
              </ItemsControl.ItemTemplate> 
             </ItemsControl> 
            </Expander> 
           </DataTemplate> 
          </ItemsControl.ItemTemplate> 
         </ItemsControl> 
        </Expander>   
       </DataTemplate> 
      </ItemsControl.ItemTemplate> 
</ItemsControl> 

あなたもListBoxItemsControlのいずれかを置き換えることができます。

ユーザーの要件に応じてGroupStyleおよびListViewを使用する別のソリューションです。

<CollectionViewSource x:Key="GroupedItems" Source="{Binding Countries}"> 
    <CollectionViewSource.GroupDescriptions> 
     <PropertyGroupDescription PropertyName="Name"/> 
    </CollectionViewSource.GroupDescriptions> 
</CollectionViewSource> 
... 
<ListView ItemsSource="{Binding Source={StaticResource GroupedItems}}" Name="Playing"> 
    <ListView.View> 
     <GridView> 
      <GridViewColumn Header="Country" Width="150" DisplayMemberBinding="{Binding Source={x:Static sys:String.Empty}}" /> 
      <GridViewColumn Header="Leagues">       
       <GridViewColumn.CellTemplate> 
        <DataTemplate> 
         <ItemsControl ItemsSource="{Binding Leagues}" Margin="25 0 0 0"> 
          <ItemsControl.ItemTemplate> 
           <DataTemplate> 
            <Grid HorizontalAlignment="Stretch" Background="#FFBCDAEC"> 
             <TextBlock FontSize="18" Padding="5" Text="{Binding Name}"/> 
            </Grid> 
           </DataTemplate> 
          </ItemsControl.ItemTemplate> 
         </ItemsControl> 
        </DataTemplate> 
       </GridViewColumn.CellTemplate> 
      </GridViewColumn> 
     </GridView> 
    </ListView.View> 
    <ListView.GroupStyle> 
     <GroupStyle> 
      <GroupStyle.ContainerStyle> 
       <Style TargetType="{x:Type GroupItem}"> 
        <Setter Property="Template"> 
         <Setter.Value> 
          <ControlTemplate> 
           <Expander IsExpanded="True"> 
            <Expander.Header> 
             <TextBlock Text="{Binding Name}" Foreground="Red" FontSize="22" VerticalAlignment="Bottom" /> 
            </Expander.Header> 
            <ItemsPresenter /> 
           </Expander> 
          </ControlTemplate> 
         </Setter.Value> 
        </Setter> 
       </Style> 
      </GroupStyle.ContainerStyle> 
     </GroupStyle> 
    </ListView.GroupStyle> 
</ListView> 

enter image description here

+0

非常に良い答え、私はあなたのコードをテストし、GroupStyleに変換しようとしている、ということは可能ですか?ヘルプはここに私のグループスタイルの構造を確認してください。あなたがここにグループ化を使用する理由http://stackoverflow.com/questions/38549818/cannot-bind-list-of-items-in-gridview-column – Heisenberg

+0

@Heisenberg私は理解できません。グループ化は他のものです。それでもGroupStyleに変換しようとします。 – AnjumSKhan

+0

グループスタイルは私にとってより良い構造を示しています。あなたのコードをグループスタイルに変換しようとします。ありがとうございました:) – Heisenberg

関連する問題