0

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; }
}

域服务 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();
    }

绑定树列表方法

 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。

下面,如图所示。HierarchicalDataTemplate Itemsource 绑定如何?

你能举个例子吗?

我不能 :(

等待你的想法...

绘图

4

1 回答 1

0

加载第一个 lavel 节点。在 HierarchicalDataTemplate 中将 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 的子节点

于 2012-10-11T11:54:50.533 回答