树视图层次结构数据模板如何-WCF Ria服务加载操作



Db类属性

[Serializable]
[EnableClientAccess()]
public class DbPersonelJobDetail
{
    public DbPersonelJobDetail()
    {
    }
    [Key]
    public Guid PersonelID { get; set; }
    public Guid JobID { get; set; }
    public string JobName { get; set; }
    public string Adi { get; set; }
}

DomainServices Linq查询

 public IQueryable<DTO.DbPersonelJobDetail> GetPersonelJobTreeList()
    {
        IQueryable<DTO.DbPersonelJobDetail> result = from p in ObjectContext.SPA_PersonelJobDetail
                                                     join c in ObjectContext.SPA_PersonelJob on p.PersonelJobID equals c.ID
                                                     select new DTO.DbPersonelJobDetail()
                                                     {
                                                         JobID=p.PersonelJobID,
                                                         JobName = c.JobName,
                                                         PersonelID=p.ID,
                                                         Adi=p.Adi
                                                     };
        return result.AsQueryable();
    }

BindTreeList方法

 public void BindTreeList()
    {
        loadOP = context.Load(context.GetPersonelJobTreeListQuery(), false);
        loadOP.Completed += loadOP_Completed;
    }
    void loadOP_Completed(object sender, EventArgs e)
    {
        treeListPersonel.ItemsSource = loadOP.Entities;
    }

我是绑定BindTreeList()方法的Treeview。

下面,如图所示。层次结构数据模板项目源绑定如何进行?

你能举个例子吗?

我不能:(

正在等待你的想法。。。

Pucture

加载第一层节点。在层次结构DataTemplate中,将ItemsSource绑定到LoadChildsConverter

<riaControls:DomainDataSource x:Name="MyData" QueryName="GetFirstLavel" 
                                  AutoLoad="True" LoadSize="50">
            <riaControls:DomainDataSource.DomainContext>
                <web:AdvDomainContext />
            </riaControls:DomainDataSource.DomainContext>
        </riaControls:DomainDataSource>
<sdk:TreeView ItemsSource="{Binding}" DataContext="{Binding ElementName=MyData, Path=Data}">
    <sdk:TreeView.ItemTemplate>
        <sdk:HierarchicalDataTemplate 
        ItemsSource="{Binding Converter={StaticResource TreeViewCollectionConverter}}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding CODE}" />
                <TextBlock Text="{Binding DESC}" />
            </StackPanel>
        </sdk:HierarchicalDataTemplate>
    </sdk:TreeView.ItemTemplate>
</sdk:TreeView>

TreeViewCollectionConverter.cs

public class TreeViewR5OBJECTCollectionConverter : IValueConverter
{
   public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        ObservableCollection<Node> nodeList = new ObservableCollection<Node>();
        if (value != null)
        {
            AdvDomainContext ctx = new AdvDomainContext();
            Node parentNode = (Node)value;
            ctx.Load(ctx.GetChildsQuery(parentNode), iop =>
                            {
                                foreach (var o in iop.Entities)
                                    nodeList.Add(o);
                            }, null);
        }
        return nodeList;
    }
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return null;
    }
}

在AdvDomainService.cs中必须具有

public IQueryable<Node> GetFirstLavel()

返回一级节点和

    public IQueryable<Node> GetChilds(Node ParentNode)

返回ParentNode 的子级

最新更新