silverlight中后台动态生成权限树结构
2011-12-01 16:41
218 查看
前台
<UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
x:Class="ttt.Leftmenu"
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"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Margin="3">
<!-- 树形标签结构定义 -->
<controls:TreeView x:Name="menu" BorderThickness="0" Background="White" FontSize="12">
</controls:TreeView>
</Grid>
</UserControl>
后台:
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;
namespace ttt{
public partial class Leftmenu : UserControl
{
#region 全局变量
// 定义按钮点击事件给主页面调用赋值
public MouseButtonEventHandler OnClick;
#endregion
#region 构造方法
/// <summary>
/// 构造方法
/// </summary>
public Leftmenu()
{
InitializeComponent();
AddTreeNode(0, null);
this.BindMenuEvent();
}
#endregion
#region Menu项绑定事件
/// <summary>
/// Menu项绑定事件
/// </summary>
void BindMenuEvent()
{
foreach (TreeViewItem rootItem in this.menu.Items)
{
foreach (TreeViewItem item in rootItem.Items)
{
if (item.Tag != null)
{
item.MouseLeftButtonUp += new MouseButtonEventHandler(item_MouseLeftButtonUp);
}
}
}
}
#endregion
#region 页面传值
/// <summary>
/// 页面传值
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void item_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (OnClick != null)
OnClick(sender, e);
}
#endregion
#region 定义实体类
/// <summary>
/// 定义实体类
/// </summary>
public class DeciveInfo
{
public int DeciveID { get; set; }
public int ParendID { get; set; }
public string DeciveName { get; set; }
public string pageName { get; set; }
}
#endregion
#region 获得动态数据的方法
/// <summary>
/// 获得动态数据的方法
/// </summary>
/// <returns></returns>
public List<DeciveInfo> GetForumData()
{
List<DeciveInfo> deviceInfoList = new List<DeciveInfo>();
deviceInfoList.Add(new DeciveInfo() { DeciveID = 1, ParendID = 0, DeciveName = "大项一" });
deviceInfoList.Add(new DeciveInfo() { DeciveID = 2, ParendID = 0, DeciveName = "大项二" });
deviceInfoList.Add(new DeciveInfo() { pageName = "UserList", DeciveID = 3, ParendID = 1, DeciveName = "大项一中1" });
deviceInfoList.Add(new DeciveInfo() { pageName = "UserList1", DeciveID = 4, ParendID = 1, DeciveName = "大项一中2" });
deviceInfoList.Add(new DeciveInfo() { pageName = "UserList", DeciveID = 5, ParendID = 2, DeciveName = "大项二1" });
deviceInfoList.Add(new DeciveInfo() { pageName = "UserList1", DeciveID = 6, ParendID = 2, DeciveName = "大项二2" });
return deviceInfoList;
}
#endregion
#region 添加叶子节点信息
/// <summary>
/// 添加叶子节点信息
/// </summary>
/// <param name="parentID">父亲节点信息</param>
/// <param name="treeViewItem"></param>
private void AddTreeNode(int parentID, TreeViewItem treeViewItem)
{
// 检索查询的集合
List<DeciveInfo> result = (from deviceInfo in GetForumData() //forumList
where deviceInfo.ParendID == parentID
select deviceInfo).ToList<DeciveInfo>();
// 查询结果不为空的情况下进行一下处理
if (result.Count > 0)
{
foreach (DeciveInfo deciveInf in result)
{
TreeViewItem objTreeNode = new TreeViewItem();
objTreeNode.Header = deciveInf.DeciveName;
// TODO 页面的导向
objTreeNode.Tag = deciveInf.pageName;
objTreeNode.DataContext = deciveInf;
//此样式将会添加的所有叶子结点上
objTreeNode.ItemContainerStyle = this.Resources["RedItemStyle"] as Style;
//添加根节点
if (treeViewItem == null)
{
menu.Items.Add(objTreeNode);
}
else
{
treeViewItem.Items.Add(objTreeNode);
}
//objTreeNode.is
AddTreeNode(deciveInf.DeciveID, objTreeNode);
}
// 给父亲节点添加属性信息
//objTreeNode.ItemContainerStyle = this.Resources["RedItemStyle"] as Style;
}
}
#endregion
}
}
以上我我做后台动态生成树形的一个操作,希望有做这个功能的朋友对你有帮助.
<UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
x:Class="ttt.Leftmenu"
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"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Margin="3">
<!-- 树形标签结构定义 -->
<controls:TreeView x:Name="menu" BorderThickness="0" Background="White" FontSize="12">
</controls:TreeView>
</Grid>
</UserControl>
后台:
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;
namespace ttt{
public partial class Leftmenu : UserControl
{
#region 全局变量
// 定义按钮点击事件给主页面调用赋值
public MouseButtonEventHandler OnClick;
#endregion
#region 构造方法
/// <summary>
/// 构造方法
/// </summary>
public Leftmenu()
{
InitializeComponent();
AddTreeNode(0, null);
this.BindMenuEvent();
}
#endregion
#region Menu项绑定事件
/// <summary>
/// Menu项绑定事件
/// </summary>
void BindMenuEvent()
{
foreach (TreeViewItem rootItem in this.menu.Items)
{
foreach (TreeViewItem item in rootItem.Items)
{
if (item.Tag != null)
{
item.MouseLeftButtonUp += new MouseButtonEventHandler(item_MouseLeftButtonUp);
}
}
}
}
#endregion
#region 页面传值
/// <summary>
/// 页面传值
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void item_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (OnClick != null)
OnClick(sender, e);
}
#endregion
#region 定义实体类
/// <summary>
/// 定义实体类
/// </summary>
public class DeciveInfo
{
public int DeciveID { get; set; }
public int ParendID { get; set; }
public string DeciveName { get; set; }
public string pageName { get; set; }
}
#endregion
#region 获得动态数据的方法
/// <summary>
/// 获得动态数据的方法
/// </summary>
/// <returns></returns>
public List<DeciveInfo> GetForumData()
{
List<DeciveInfo> deviceInfoList = new List<DeciveInfo>();
deviceInfoList.Add(new DeciveInfo() { DeciveID = 1, ParendID = 0, DeciveName = "大项一" });
deviceInfoList.Add(new DeciveInfo() { DeciveID = 2, ParendID = 0, DeciveName = "大项二" });
deviceInfoList.Add(new DeciveInfo() { pageName = "UserList", DeciveID = 3, ParendID = 1, DeciveName = "大项一中1" });
deviceInfoList.Add(new DeciveInfo() { pageName = "UserList1", DeciveID = 4, ParendID = 1, DeciveName = "大项一中2" });
deviceInfoList.Add(new DeciveInfo() { pageName = "UserList", DeciveID = 5, ParendID = 2, DeciveName = "大项二1" });
deviceInfoList.Add(new DeciveInfo() { pageName = "UserList1", DeciveID = 6, ParendID = 2, DeciveName = "大项二2" });
return deviceInfoList;
}
#endregion
#region 添加叶子节点信息
/// <summary>
/// 添加叶子节点信息
/// </summary>
/// <param name="parentID">父亲节点信息</param>
/// <param name="treeViewItem"></param>
private void AddTreeNode(int parentID, TreeViewItem treeViewItem)
{
// 检索查询的集合
List<DeciveInfo> result = (from deviceInfo in GetForumData() //forumList
where deviceInfo.ParendID == parentID
select deviceInfo).ToList<DeciveInfo>();
// 查询结果不为空的情况下进行一下处理
if (result.Count > 0)
{
foreach (DeciveInfo deciveInf in result)
{
TreeViewItem objTreeNode = new TreeViewItem();
objTreeNode.Header = deciveInf.DeciveName;
// TODO 页面的导向
objTreeNode.Tag = deciveInf.pageName;
objTreeNode.DataContext = deciveInf;
//此样式将会添加的所有叶子结点上
objTreeNode.ItemContainerStyle = this.Resources["RedItemStyle"] as Style;
//添加根节点
if (treeViewItem == null)
{
menu.Items.Add(objTreeNode);
}
else
{
treeViewItem.Items.Add(objTreeNode);
}
//objTreeNode.is
AddTreeNode(deciveInf.DeciveID, objTreeNode);
}
// 给父亲节点添加属性信息
//objTreeNode.ItemContainerStyle = this.Resources["RedItemStyle"] as Style;
}
}
#endregion
}
}
以上我我做后台动态生成树形的一个操作,希望有做这个功能的朋友对你有帮助.
相关文章推荐
- TP支持菜单动态生成RBAC权限系统数据库结构设计方案
- php后台管理,结合权限,动态生成栏目列表
- php后台管理,结合权限,动态生成栏目列表
- 使用 HighCharts 动态获取后台数据生成图表
- 后台获取前台动态生成控件的值
- 浅谈后台中动态生成Table
- 树形此博文包含图片结构数据后台处理:一次循环生成树
- 由后台action。servlet动态生成HTML代码穿向前台的方式是何等丑陋
- 稳扎稳打Silverlight(65) - 5.0绑定之通过 ICustomTypeProvider 绑定动态生成的属性
- C#后台动态生成CheckBoxList
- SilverLight企业应用框架设计【四】实体层设计+为客户端动态生成服务代理(自己实现RiaService)
- 构造网站后台,我的EXT+EFS模式(一)----配置环境与初试动态生成控件
- 后台动态生成GridView列和模版
- js动态生成树形结构
- Silverlight 在页面上动态生成控件
- js通过后台配置动态生成html table表格
- Silverlight Visifire控件 .net后台控制aspx页面控件的显示与隐藏,动态给控件赋值,选定默认值的设定
- 【转载】【权限控制】角色访问动态生成用户权限菜单树
- dtree动态生成树型结构
- 后台动态生成文章名,前台js实现点文章名进入指定文章,打通前台与后台的操作。