Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何防止ItemCount重复?_C#_Wpf - Fatal编程技术网

C# 如何防止ItemCount重复?

C# 如何防止ItemCount重复?,c#,wpf,C#,Wpf,我有一个与一个国家相关的匹配列表。现在在迭代中,我为每一场比赛分配这个国家,例如: Team A = Italy Team B = Italy 我在GridView中绑定此匹配项,如下所示: <Expander IsExpanded="True" Background="#4F4F4F"> <Expander.Header> <StackPanel Orientation="Horizontal" Height="22"> <T

我有一个与一个国家相关的匹配列表。现在在迭代中,我为每一场比赛分配这个国家,例如:

Team A = Italy
Team B = Italy
我在GridView中绑定此匹配项,如下所示:

<Expander IsExpanded="True" Background="#4F4F4F">
  <Expander.Header>
    <StackPanel Orientation="Horizontal" Height="22">
      <TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="White" FontSize="22" VerticalAlignment="Bottom" />
      <TextBlock Text="{Binding ItemCount}" FontSize="22" Foreground="Orange" FontWeight="Bold" FontStyle="Italic" Margin="10,0,0,0" VerticalAlignment="Bottom" />
      <TextBlock Text=" match" FontSize="22" Foreground="White" FontStyle="Italic" VerticalAlignment="Bottom" />
    </StackPanel>
  </Expander.Header>
  <ItemsPresenter />
</Expander>


不管怎么说,名字就是国名,问题是ItemCount两次抢夺意大利。我需要防止在xaml中出现这种情况,并且不显示重复的项目,这可能吗?

您的问题不明确,但我猜您没有根据您的城市名称对结果进行分组。

我继续,假设您有一个标记为
团队的某种类型的通用
列表

试试这个:

List<Team> teams = new List<Team>
{
    new Team {Name = "Italy"},
    new Team {Name = "France"},
    new Team {Name = "Italy"}
};

var distinctList = teams.Select(team => team.Name)
                        .Distinct()
                        .Select(team => new Team {Name = team})
                        .OrderBy(team => team.Name)
                        .ToList();

您没有提供足够的详细信息。我需要成为诺查丹玛斯才能回答你能在你设置
ItemCount
的地方发布代码吗?XAML在这里看起来基本不相关。。。它只显示您已经计算的内容。清单上的C#代码如何?我已经发布了一个关于这种情况的新问题,@LieroDon不会再提出这样的问题。这里有一个编辑按钮。
this.ItemCount = distinctList.Count();