我的问题是这个,我有一个课程匹配:
Match.cs
public class Match
{
public int Id { get; set; }
public Team Team_1 { get; set; }
public Team Team_2 { get; set; }
public string Date { get; set; }
public string Hour { get; set; }
public string Local { get; set; }
public string Statium { get; set; }
}
并且这个类有两个对象Team
,在Team i中有这个属性:
Team.cs
public class Team
{
public int Id { get; set; }
public string Name { get; set; }
public string Image { get; set; }
...
我尝试在我的视图中绑定Match对象:
<ListBox Name="lbMatches" Height="480" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<StackPanel Width="60" Orientation="Vertical">
<TextBlock Text="{Binding Date}" FontFamily="Segoe WP Semibold" />
<TextBlock Text="{Binding Hour}" FontFamily="Segoe WP Semibold"/>
</StackPanel>
<TextBlock VerticalAlignment="Center" Text="Brazil" FontSize="32" FontFamily="Segoe WP Semibold" Margin="20,0,10,0"/>
<Image Source="{Binding Thumb}"/>
<TextBlock VerticalAlignment="Center" Text="x" FontSize="32" Margin="10,0" Opacity="0.8"/>
<Image Source="/Assets/team_image/thumbs/croacia.png"/>
<TextBlock VerticalAlignment="Center" Text="Croatia" FontSize="32" FontFamily="Segoe WP Semibold" Margin="10,0,20,0"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
但是有一个关键的duvid,我是如何让一个比赛绑定队伍的名字?绑定Match的团队如何制作这个?
答案 0 :(得分:0)
您可以导航到绑定中从Match
到Team
的关系,例如
<TextBlock Text="{Binding Team_1.Name}"/>
答案 1 :(得分:0)
您没有设置列表框的ItemSsource。接下来,您可以通过以下方式访问Team属性:“Team_1.attribute”
这是一个例子:
xaml:
<ListBox Name="lbMatches" Height="480" ItemSource="{binding myMatch}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<StackPanel Width="60" Orientation="Vertical">
<TextBlock Text="{Binding Team_1.Name}" FontFamily="Segoe WP Semibold" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>