使用silverlight+wcf完成动态的树形控件的绑定,谁能给个实例?急!

HFtime 2010-09-13 10:59:02
实例!谢谢!
...全文
145 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jv9 2010-09-14
  • 打赏
  • 举报
回复
楼主可以参考以下教程:

[Silverlight]TreeView控件——动态加载子项

http://www.silverlightchina.net/html/tips/2010/0510/1110.html

Silverlight使用反射实现TreeView动态导航

http://www.silverlightchina.net/html/tips/2010/0630/1364.html
abis 2010-09-14
  • 打赏
  • 举报
回复


if exists (select * from sysobjects where id = OBJECT_ID('[t_sys_Menu]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)
DROP TABLE [t_sys_Menu]

CREATE TABLE [t_sys_Menu] (
[ID] [uniqueidentifier] NULL DEFAULT (newid()),
[MenuCode] [varchar] (100) NOT NULL,
[MenuName] [nvarchar] (200) NULL,
[PMenuCode] [varchar] (100) NULL,
[FileName] [varchar] (200) NULL,
[FileExt] [varchar] (200) NULL,
[Ico] [varchar] (200) NULL,
[ImgIndex] [int] NULL DEFAULT ((-1)),
[DisplayOrder] [varchar] (100) NULL,
[IsExpand] [char] (1) NULL DEFAULT (1),
[IsUse] [char] (1) NULL DEFAULT (1))

ALTER TABLE [t_sys_Menu] WITH NOCHECK ADD CONSTRAINT [PK_t_sys_Menu] PRIMARY KEY NONCLUSTERED ( [MenuCode] )
INSERT [t_sys_Menu] ([ID],[MenuCode],[MenuName],[PMenuCode],[Ico],[ImgIndex],[IsExpand],[IsUse]) VALUES ( '894e5592-856c-4273-84f3-ba5e39c1e627','0','根节点','ZZZZ','TechnicalMeetings.png',-1,'1','1')
INSERT [t_sys_Menu] ([ID],[MenuCode],[MenuName],[PMenuCode],[Ico],[ImgIndex],[IsExpand],[IsUse]) VALUES ( 'ccce25bb-7965-4af4-88a6-43ccdb673d55','10','公共查询','0','3Drafts.png',1,'0','1')
INSERT [t_sys_Menu] ([ID],[MenuCode],[MenuName],[PMenuCode],[FileName],[FileExt],[Ico],[ImgIndex],[IsExpand],[IsUse]) VALUES ( '1d6cbc07-da29-4989-86ad-efda00db3a7c','1001','查询1','10','ljkkl.aspx','xap','Travel.png',-1,'1','1')
INSERT [t_sys_Menu] ([ID],[MenuCode],[MenuName],[PMenuCode],[FileName],[FileExt],[Ico],[ImgIndex],[IsExpand],[IsUse]) VALUES ( '8713a1c6-99d7-46cd-b114-0af56faec5db','1002','查询2','10','111','xap','sport_football.png',-1,'1','1')
INSERT [t_sys_Menu] ([ID],[MenuCode],[MenuName],[PMenuCode],[FileExt],[Ico],[ImgIndex],[IsExpand],[IsUse]) VALUES ( '9878e06e-1e83-4366-b7d9-65a85ff27234','20','文件输入','0','xap','search.png',1,'1','1')
INSERT [t_sys_Menu] ([ID],[MenuCode],[MenuName],[PMenuCode],[FileName],[FileExt],[Ico],[IsExpand],[IsUse]) VALUES ( '65d7a94d-45eb-41a0-869d-65029c686b9c','2001','输入子菜单','20','123456','xaml','search.png','0','0')
INSERT [t_sys_Menu] ([ID],[MenuCode],[MenuName],[PMenuCode],[FileName],[FileExt],[Ico],[ImgIndex],[IsExpand],[IsUse]) VALUES ( '9bb78503-b8b2-4c11-b717-792bccb716df','99','系统设置','0','abcde','xaml','TechnicalMeetings.png',1,'0','1')
INSERT [t_sys_Menu] ([ID],[MenuCode],[MenuName],[PMenuCode],[FileName],[FileExt],[IsExpand],[IsUse]) VALUES ( 'c9810638-ba2a-4056-891a-d71bc89d564c','9901','换肤功能','99','abcdefg','xaml','0','1')

abis 2010-09-14
  • 打赏
  • 举报
回复


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.Windows.Navigation;

using System.Windows.Media.Imaging;
using Telerik.Windows.Controls;
using System.ServiceModel.DomainServices.Client;
using ABISCustom.Web;

namespace ABISAdmin.Menu
{
public partial class PageMenuList : Page
{
//t_sys_Menu mInfo = new t_sys_Menu() { ID = null, MenuCode = "0", MenuName = "根节点", PMenuCode = "0", FileName = "", FileExt = "", Ico = "", ImgIndex = 0, IsExpand = "1", IsUse = "1" };

DomainServiceCustom customContext = new DomainServiceCustom();
public List<t_sys_Menu> listMenu = new List<t_sys_Menu>();
TreeViewItem TreeNodeTop = new TreeViewItem();

ChildWindowMenuAdd cwMenuAdd = new ChildWindowMenuAdd();
ChildWindowMenuEdit cwMenuEdit = new ChildWindowMenuEdit();
public PageMenuList()
{
InitializeComponent();

showTree();

this.cwMenuAdd.Closed += new EventHandler(cwMenuAdd_Closed);
this.cwMenuEdit.Closed += new EventHandler(cwMenuEdit_Closed);
Loaded += new RoutedEventHandler(MainPage_Loaded);

}

// 当用户导航到此页面时执行。
protected override void OnNavigatedTo(NavigationEventArgs e)
{

}

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
//每次激活时就运行一次
//showTree();
}

void showTree()
{
//清除树的所有节点
tvMenu.Items.Clear();
listMenu.Clear();
tvMenu.DataContext = null;

//从数据库里调数据
var query = (from menu in customContext.GetT_sys_MenuQuery()
select menu);
LoadOperation<t_sys_Menu> contact = customContext.Load(query);
contact.Completed += new EventHandler(contact_Completed);

}

void contact_Completed(object sender, EventArgs e)
{
LoadOperation<t_sys_Menu> contact = (LoadOperation<t_sys_Menu>)sender;

listMenu = (from menu in contact.Entities
select menu).AsQueryable().ToList();

AddTreeNode("ZZZZ", null);

//指定选择项开始=========================================
RadTreeViewItem tr = new RadTreeViewItem();
tr = tvMenu.Items[0] as RadTreeViewItem;
tr.IsSelected = true;
//指定选择项结束=========================================

}

private void AddTreeNode(string parentID, RadTreeViewItem treeViewItemTemp)
{

List<t_sys_Menu> result = (from menuInfo in listMenu
where menuInfo.PMenuCode == parentID
select menuInfo).ToList<t_sys_Menu>();

if (result.Count > 0)
{

foreach (t_sys_Menu menuinfo in result)
{
RadTreeViewItem objTreeNode = new RadTreeViewItem();
objTreeNode.Header = menuinfo.MenuName + " [" + menuinfo.MenuCode + "]";

objTreeNode.DataContext = menuinfo;
objTreeNode.IsExpanded = true;

if (menuinfo.Ico.ToString().Trim() != "" && menuinfo.Ico != null)
{
objTreeNode.DefaultImageSrc ="../Images/Small/" + menuinfo.Ico.ToString().Trim();
//objTreeNode.DefaultImageSrc = new BitmapImage(new Uri("../Images/Small/" + menuinfo.Ico.ToString().Trim(), UriKind.Relative));

}

if (menuinfo.IsUse != "1")
{
objTreeNode.Foreground = new SolidColorBrush(Colors.Red);
objTreeNode.Header += " [停]";
}

if (treeViewItemTemp == null)
{
tvMenu.Items.Add(objTreeNode);

}
else
{
treeViewItemTemp.Items.Add(objTreeNode);
}

AddTreeNode(menuinfo.MenuCode, objTreeNode);
}

}


}

private void buttonAdd_Click(object sender, RoutedEventArgs e)
{
RadTreeViewItem item = tvMenu.SelectedItem as RadTreeViewItem;
t_sys_Menu menuModal = item.DataContext as t_sys_Menu;
cwMenuAdd.menuInfoCwadd.PMenuCode = cwMenuAdd.textBoxPMenuCode.Text = menuModal.MenuCode.ToString().Trim();
cwMenuAdd.textBoxPMenuName.Text = menuModal.MenuName.ToString().Trim();

cwMenuAdd.Show();



}

void cwMenuAdd_Closed(object sender, EventArgs e)
{

if (cwMenuAdd.DialogResult == true)
{

customContext.t_sys_Menus.Add(cwMenuAdd.menuInfoCwadd);
customContext.SubmitChanges(OnSubmitCompleted, null);
}
else
{

}

}

void cwMenuEdit_Closed(object sender, EventArgs e)
{

if (cwMenuEdit.DialogResult == true)
{
t_sys_Menu menuInfo = customContext.t_sys_Menus.Single(c => c.MenuCode == cwMenuEdit.strSessCode);

menuInfo.MenuCode = cwMenuEdit.textBoxMenuCode.Text.ToString().Trim();
menuInfo.MenuName = cwMenuEdit.textBoxMenuName.Text.ToString().Trim();
menuInfo.FileName = cwMenuEdit.textBoxFileName.Text.ToString().Trim();
menuInfo.FileExt = cwMenuEdit.comboBoxDataWJLX._selectItemCode.ToString().Trim();
menuInfo.Ico = cwMenuEdit.textBoxIco.Text.ToString().Trim();
menuInfo.IsExpand = cwMenuEdit.comboBoxDataSFZK._selectItemCode.ToString().Trim();
menuInfo.IsUse = cwMenuEdit.comboBoxDataSFSY._selectItemCode.ToString().Trim();


customContext.SubmitChanges(OnSubmitCompleted, null);
}
else
{

}


//buttonShow_Click(null, null);

}

private void buttonDel_Click(object sender, RoutedEventArgs e)
{
RadTreeViewItem item = tvMenu.SelectedItem as RadTreeViewItem;
t_sys_Menu menuModal = item.DataContext as t_sys_Menu;

if (menuModal.MenuCode == "0")
{
MessageBox.Show("不能删除根节点,删除失败!");
return;
}

if (MessageBox.Show("是否删除选中的节点?", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
{
customContext.t_sys_Menus.Remove(menuModal);
customContext.SubmitChanges(OnSubmitCompleted, null);

//MessageBox.Show("操作成功!");

}

}

private void buttonEdit_Click(object sender, RoutedEventArgs e)
{
RadTreeViewItem item = tvMenu.SelectedItem as RadTreeViewItem;
t_sys_Menu menuModal = item.DataContext as t_sys_Menu;

if (menuModal.MenuCode == "0")
{
MessageBox.Show("不能编辑根节点!");
return;
}
else
{
cwMenuEdit.strSessCode = menuModal.MenuCode.ToString().Trim();
cwMenuEdit.Show();

}


}

private void buttonShow_Click(object sender, RoutedEventArgs e)
{
showTree();
}

public void OnSubmitCompleted(SubmitOperation so)
{
this.showTree();
MessageBox.Show("提交成功!");
}


}
}

abis 2010-09-14
  • 打赏
  • 举报
回复

<navigation:Page xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" x:Class="ABISAdmin.Menu.PageMenuList"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
d:DesignWidth="640" d:DesignHeight="480"
Title="PageMenuList Page" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">


<Grid x:Name="LayoutRoot" >
<Grid Name="gridMain" ShowGridLines="False" >

<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition Height="60"></RowDefinition>
</Grid.RowDefinitions>
<telerik:RadTreeView Margin="0" Name="tvMenu" VerticalAlignment="Top" IsLineEnabled="True" Grid.Row="0" >
</telerik:RadTreeView>

<Grid Margin="1,1,1,1" Name="gridBottom" Background="#FFEEEEEE" Grid.Row="1">
<telerik:RadButton Content="编辑" FontSize="12" Height="30" HorizontalAlignment="Left" Margin="20,15,0,0" Name="buttonEdit" VerticalAlignment="Top" Width="90" Click="buttonEdit_Click" />
<telerik:RadButton Content="删除" FontSize="12" Height="30" HorizontalAlignment="Left" Margin="120,15,0,0" Name="buttonDel" VerticalAlignment="Top" Width="90" Click="buttonDel_Click" />
<telerik:RadButton Content="增加子菜单" Height="30" HorizontalAlignment="Right" Margin="0,15,20,0" Name="buttonAdd" VerticalAlignment="Top" Width="90" FontSize="12" Click="buttonAdd_Click" />
<telerik:RadButton Content="刷新" Height="30" HorizontalAlignment="Right" Margin="0,15,120,0" Name="buttonShow" VerticalAlignment="Top" Width="90" FontSize="12" Click="buttonShow_Click" />
</Grid>

</Grid>

</Grid>
</navigation:Page>












8,735

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧