博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
lightswitch 添加 TreeView 控件
阅读量:6716 次
发布时间:2019-06-25

本文共 6894 字,大约阅读时间需要 22 分钟。

代码片段

  

using Microsoft.LightSwitch.Framework.Client;using Microsoft.LightSwitch.Presentation;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 LightSwitchApplication.TreeViewControl{    public partial class DepartmentTreeViewControl : UserControl    {        public DepartmentTreeViewControl()        {            InitializeComponent();        }        private void treeViewControl_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs e)        {            var selectItem = (LightSwitchApplication.Department)treeViewControl.SelectedItem;            var type1 = selectItem.GetType();            var context = (IContentItem)this.DataContext;            var screen = context.Screen;            var data = (VisualCollection
)screen.Details.Properties["DepartmentTree"].Value; data.SelectedItem = selectItem; //data.text= selectItem.Details.Properties["Id"].Value; } }}

  

using Microsoft.LightSwitch;using System;using System.Collections.Generic;using System.Collections.ObjectModel;using System.Diagnostics;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Ink;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;namespace LightSwitchApplication.TreeViewControl{    public class EntityCollectionValueConverter : IValueConverter    {        public object Convert(object value,            Type targetType,            object parameter,            System.Globalization.CultureInfo culture)        {            string strErrorMessage                = "Converter parameter should be set to the property name that will serve as source of data";            IEntityObject entity = value as IEntityObject;            if (entity == null)                throw new ArgumentException("The converter should be using an entity object");            string sourcePropertyName = parameter as string;            if (string.IsNullOrWhiteSpace(sourcePropertyName))                throw new ArgumentException(strErrorMessage);            // Enumerate the source property using logic dispatcher             // and prepare the collection of entities that the control will bind to            var entities = new ObservableCollection
(); var temporaryEntites = new List
(); entity.Details.Dispatcher.BeginInvoke(delegate { IEntityCollection eCollection = entity.Details.Properties[sourcePropertyName].Value as IEntityCollection; if (eCollection == null) { Debug.Assert(false, "The property " + sourcePropertyName + " is not an entity collection"); return; } // Now we are on the logic thread. We cannot just stuff the observable collection // with entities because the collection will immediately raise Changed events // and this will result in invalid cross-thread access. So we'll use a temporary collection // and copy the entites again on the UI thread foreach (IEntityObject e in eCollection) { temporaryEntites.Add(e); } Microsoft.LightSwitch.Threading.Dispatchers.Main.BeginInvoke(delegate { // I wish ObservableCollection had an AddRange() method... foreach (IEntityObject e in temporaryEntites) { entities.Add(e); } }); }); return entities; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } }}

 片段2

public partial class CategoriesListDetail    {        private TreeView treeView = null;        partial void CategoriesListDetail_InitializeDataWorkspace(List
saveChangesTo) { // Write your code here. } partial void CategoriesListDetail_Created() { // Write your code here. this.P_Name = ""; this.RootNode.Load(); this.FindControl("TreeViewControl").ControlAvailable += ((o, e) => { treeView = e.Control as TreeView; treeView.BorderThickness = new Thickness(1); if (treeView.Items.Count == 0) { foreach (var item in this.RootNode) { TreeViewItem rootItem = new TreeViewItem() { Header = item.Name, Tag = item.Id }; treeView.Items.Add(rootItem); } treeView.SelectedItemChanged += new RoutedPropertyChangedEventHandler
(TreeViewItem_SelectedItemChanged); } }); } private void TreeViewItem_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs e) { var parentItem = e.NewValue as TreeViewItem; this.P_Name = (string)parentItem.Header; this.p_id = (int)parentItem.Tag; ///when collection is refreshed the event SelectedNodeEmployees_Changed is hooked up ///do not use Load method to avoid caching this.SelectedChildrenNodes.Refresh(); } partial void SelectedChildrenNodes_Changed(NotifyCollectionChangedEventArgs e) { if (treeView != null) { Dispatchers.Main.BeginInvoke(() => { var parentItem = treeView.SelectedItem as TreeViewItem; if (parentItem != null) { if (parentItem.Items.Count == 0 && this.SelectedChildrenNodes.Count() > 0) { foreach (var item in this.SelectedChildrenNodes) //.Where(act => act.Title != "???") { TreeViewItem newChildItem = new TreeViewItem() { Header = item.Name, Tag = item.Id }; parentItem.Items.Add(newChildItem); } } } }); } } }

  

 

转载地址:http://ankmo.baihongyu.com/

你可能感兴趣的文章
Storm概念学习系列之storm的特性
查看>>
JQuery------$.get()和$.post()传递数据的使用方法
查看>>
Atitti 数据库事务处理 attilax总结
查看>>
Android中动态设置GridView的列数、列宽和行高
查看>>
oracle中修改表名
查看>>
PhpStorm下Laravel代码智能提示
查看>>
IntelliJ IDEA中运行Tomcat报内存溢出(java.lang.OutOfMemoryError: PermGen space)
查看>>
转】 Kafka文件存储机制那些事
查看>>
jquery怎么在点击li标签之后添加一个在class,点击下一个li时删除上一个class?...
查看>>
在Docker中运行web应用
查看>>
spring boot 框架 启动更新项目,以及生成 "实体_"文件
查看>>
android启动模式
查看>>
arcgis api for js入门开发系列七图层控制
查看>>
JavaScript EventLoop
查看>>
新安装个Myeclipse,导入以前做的程序后程序里好多错,提示The import java.util cannot be resolved...
查看>>
第六篇:GPU 并行优化的几种典型策略
查看>>
Cronolog 分割 Tomcat8 Catalina.out日志 (转)
查看>>
Linux Platform驱动模型(二) _驱动方法
查看>>
商城系统购物车功能分析实现
查看>>
Java之Builder模式(并用OC实现了这种模式)
查看>>