私は試合のライブ結果を得ることを可能にするアプリケーションを作った。 今、各試合の組織はこれです:複数のGroupDescriptionを挿入するにはどうすればよいですか?
Nation->League->Match list
だから私はLeague
のコンテナをされ、そしてLeague
はMatch
のコンテナであるNation
をしました。あなたが見ることができますどのように
<Window x:Class="GroupBox_Header.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GroupBox_Header"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid Margin="10">
<ListView Name="lvUsers">
<ListView.View>
<GridView>
<GridViewColumn Header="Home Team" Width="50" DisplayMemberBinding="{Binding HomeTeam}" />
<GridViewColumn Header="Away Team" Width="50" DisplayMemberBinding="{Binding AwayTeam}" />
</GridView>
</ListView.View>
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Expander IsExpanded="True">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="Gray" FontSize="22" VerticalAlignment="Bottom" />
<TextBlock Text="{Binding ItemCount}" FontSize="22" Foreground="Green" FontWeight="Bold" FontStyle="Italic" Margin="10,0,0,0" VerticalAlignment="Bottom" />
<TextBlock Text=" Items" FontSize="22" Foreground="Silver" FontStyle="Italic" VerticalAlignment="Bottom" />
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Expander IsExpanded="True">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding League}" FontWeight="Bold" Foreground="Gray" FontSize="22" VerticalAlignment="Bottom" />
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
</Grid>
が、この中で私が保存し、GroupStyle
定義がListView
があります:前に言ったように私が最初にやったことは、私は、コンテナの結果を達成することを可能にするXAML
構造を作成しましたすべてNation
です。デモソリューションでXAML
を試して、結果を確認することができます。
public struct League
{
public string Name { get; set; }
}
public struct Country
{
public string Name { get; set; }
public League League;
}
は非常に非常に簡単です、すべてのリーグを救うためLeague
構造体や国家のためCountry
構造体:
この後、私は私が値を格納できるようにする構造体を作成しました。私はこのようにCountry
に付加価値化しました:
List<Country> items = new List<Country>();
items.Add(new Country() { Name = "Italy", League = { Name = "Serie A"} });
items.Add(new Country() { Name = "Italy", League = { Name = "Serie B" } });
items.Add(new Country() { Name = "England", League = { Name = "Premiere League" } });
items.Add(new Country() { Name = "Spain", League = { Name = "Primeira Division" } });
lvUsers.ItemsSource = items;
は、だから私は実際にリストItaly (2), England, Spain
を持っています。次にListView
(XAMLコントロール)のItemsSource
にitems
を挿入しました。 Nation
名としてヘッダグループを作成し、私はCollectionView
を使用しましたために
:
CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(lvUsers.ItemsSource);
PropertyGroupDescription groupNations = new PropertyGroupDescription("Name");
このコードは、私は複数のヘッダを作成することができ、その結果は、私がしたい正確に何です。また、私はNation
コンテナ(ヘッダ)にsub-header
League
名としてインサートである必要なものを起こす」、League
のために同じことをやった:
view.GroupDescriptions.Add(groupNations);
PropertyGroupDescription groupCompetions = new PropertyGroupDescription("League");
view.GroupDescriptions.Add(groupNations);
が、実際にこれが結果です:
あなたが唯一の国家ヘッダを見ることができますどのようにが表示されますが、League
ヘッダはNation
ヘッダー内に表示されません。私は間違って何をしていますか?
どのようにあなたは下になるのではなく、内側にあると確信していますか?あなたがネイションを閉じれば、それはなくなるのだろうか? – Paparazzi
@パパラッチそれについてはわかりませんが、おそらく別の問題です。今はリーグの名前を印刷できません。 – Dillinger