0

我正在使用 Gridview 来显示我从 WCF 服务获得的一些事件项。我使用的代码

代码隐藏:

List<GroupInfoList<object>> groups = new List<GroupInfoList<object>>();
ServiceReference1.Service1Client c = new ServiceReference1.Service1Client();
List<Tag> tags=(await c.GetUserTagsAsync(u.id)).ToList();
var q = from t in tags
                orderby ((Tag)t ).tag1
                group t by ((Tag)t).tag1 into g
                select new { GroupName = g.Key, Items = g };
        foreach (var g in q)
        {
            GroupInfoList<object> info = new GroupInfoList<object>();
            info.Key = g.GroupName;
            foreach (var item in g.Items)
            {
                info.Add(item);
            }
            groups.Add(info);
        }
        cvs1.Source = groups;

public class GroupInfoList<T> : List<object>
{

    public object Key { get; set; }


    public new IEnumerator<object> GetEnumerator()
    {
        return (System.Collections.Generic.IEnumerator<object>)base.GetEnumerator();
    }
}

WCF 签名:

List<Event> GetEventsByTag(string tag);   
List<Tag> GetUserTags(Guid uid); 

XAML

<GridView x:Name="ItemsByCategory"  VerticalAlignment="Bottom" 
                                  ItemsSource="{Binding Source={StaticResource cvs1}}"
                                  BorderBrush="Gray" BorderThickness="1">

        <GridView.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </GridView.ItemsPanel>

        <GridView.ItemTemplate>
            <DataTemplate>
                <Grid HorizontalAlignment="Left" Background="White">
                    <StackPanel Orientation="Horizontal" Margin="10,10,0,0">                            
                        <Image Source="{Binding Image}" Height="60" Width="60" VerticalAlignment="Center" Margin="0,0,10,0"/>
                        <StackPanel Margin="0,0,0,0" Orientation="Vertical">
                            <TextBlock TextWrapping="Wrap" Style="{StaticResource ItemTitleStyle}"  Width="200" VerticalAlignment="Center" Text="{Binding XXXXXXXX}" 
                                       HorizontalAlignment="Left" FontFamily="Segoe UI" />
                        </StackPanel>
                    </StackPanel>
                </Grid>
            </DataTemplate>
        </GridView.ItemTemplate>

        <GridView.GroupStyle>
            <GroupStyle>
                <GroupStyle.HeaderTemplate>
                    <DataTemplate>
                        <Grid Background="White" Margin="0">
                            <TextBlock Text='{Binding Key}' Foreground="Gray" FontSize="25" Margin="5" />
                        </Grid>
                    </DataTemplate>
                </GroupStyle.HeaderTemplate>

                <GroupStyle.Panel>
                    <ItemsPanelTemplate>
                        <VariableSizedWrapGrid Orientation="Vertical"/>
                    </ItemsPanelTemplate>
                </GroupStyle.Panel>
            </GroupStyle>
        </GridView.GroupStyle>
    </GridView>

问题是我不知道在 TextBlock(标有 XXX)中的数据绑定中放入什么,以便我可以将它绑定到来自我的源的每个事件的标题属性?

4

1 回答 1

1

终于修好了

在 C# 中,我将代码修改为这样

foreach (var g in q)
        {
            GroupInfoList<object> info = new GroupInfoList<object>();
            info.Key = g.GroupName;
            foreach (var item in g.Items)
            {
                foreach (var ev in item.Events)
                {
                    info.Add(ev);
                }
            }
            groups.Add(info);

在 XAML 中

<TextBlock TextWrapping="Wrap" Style="{StaticResource ItemTitleStyle}"  Width="200" VerticalAlignment="Center" Text="{Binding title}" 
                                       HorizontalAlignment="Left" FontFamily="Segoe UI" />
于 2012-04-14T08:32:00.010 回答