首页 新闻 赞助 找找看

关于Silverlight 绑定TREEVIEW的问题。

0
悬赏园豆:5 [已关闭问题] 关闭于 2012-05-29 14:00

我设计一个Sivlerlight 的程序,想取得一个表的数据绑定到Treeview 控件上面,使用RIA service ,为了便于查看数据,我同时增加了一个Gridview 控件,现在是gridview 可以显示数据,我想先把treeview的根节点绑定,但是为什么不显示那? gridview 是可以显示数据的。

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ServiceModel.DomainServices.Client;
using org.Web;

namespace org
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent ();
           this.bind ();
            //this.Loaded += new RoutedEventHandler ( MainPage_Loaded );
        }

            void bind()
        {
            ORGservice dc = new ORGservice ();

            dataGrid1.ItemsSource = dc.View_oraganizations;
            dc.Load ( dc.GetView_oraganizationQuery () );

            var sec = from c in dc.View_oraganizations
                      where c.parentid.ToString()=="0"
                      select c;

            List<View_oraganization> lst = sec.ToList ();

            if ( lst.Count > 0 )
            {

                foreach ( View_oraganization nodeid_ in lst )
                {
                    TreeViewItem objTreeNode = new TreeViewItem ();
                    objTreeNode.DataContext = nodeid_.Node;
                    objTreeNode.Tag = nodeid_.tag;
                    objTreeNode.Header = nodeid_.Node;
                    treeView1.Items.Add ( objTreeNode );
                   
                }
            }
           
        }
    }

奇怪那

问题补充:

现在我验证了,一下,如果不使用 .edmx 和 domainservice.cs 而直接绑定list <> 类 是没问题的。

我断点了一下,确实没有数据赋给treeview ,但是为什么gridview 可以拿到数据那?

figofeng的主页 figofeng | 初学一级 | 园豆:5
提问于:2012-05-04 11:50
< >
分享
所有回答(1)
0
对照下面这种方式改一下,就几个地方:
xaml:
<sdk:TreeView Width="400" Height="300" ItemsSource="{Binding}" ItemTemplate="{StaticResource NameTemplate}" x:Name="myTreeView" /> cs: DataGridTopic.ChildTopics.Add( new Topic("How to: Display and Configure Row Details in the DataGrid Control", 1)); Topics.Add(DataGridTopic); myTreeView.DataContext = Topics;
悟行 | 园豆:12559 (专家六级) | 2012-05-04 13:19

没明白 datagrid 没有实际意义,我就是看看数据,真实的目的是吧数据绑定到treeview。

支持(0) 反对(0) figofeng | 园豆:5 (初学一级) | 2012-05-04 13:48

@figofeng: 上面就是告诉你怎么把数据绑定到treeview上啊。

支持(0) 反对(0) 悟行 | 园豆:12559 (专家六级) | 2012-05-04 14:04

@荒野的呼唤: 绑定数据显示没问题,现在的问题是数据为空,我第一次使用 .edmx 和 domainservice.cs 来实现RIA 级别的数据通信,不知道为什么datagrid 可以获得数据为什么 treeview 不能。您有相关的经验吗?

支持(0) 反对(0) figofeng | 园豆:5 (初学一级) | 2012-05-04 15:52

@figofeng: 已经搞定了,不用ria 了改为 linq 2 sql & wcf 来实现了。

支持(0) 反对(0) figofeng | 园豆:5 (初学一级) | 2012-05-04 16:44
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册