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

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

代码片段

  

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

  

 

转载于:https://www.cnblogs.com/neozhu/p/3692003.html

你可能感兴趣的文章
CSS技巧:Flex弹性布局大型攻略
查看>>
UVC摄像头-学习
查看>>
深入理解多线程(四)—— Moniter的实现原理
查看>>
前端面试中常考的源码实现
查看>>
vue基于viewer实现的图片查看器
查看>>
HTML、CSS、JavaScript
查看>>
Html5的新特性总结
查看>>
来一个阿里妈妈字体图标的简单说明书吧
查看>>
git 入门教程之撤销更改
查看>>
React在线编辑国际化文本
查看>>
了解多线程!
查看>>
Android Jetpack架构组件之 Paging(使用、源码篇)
查看>>
Day 4
查看>>
面向对象(理解对象)——JavaScript基础总结(一)
查看>>
写项目代码之前必须要做的事
查看>>
别装啦!一看就知道你要跳槽了.....
查看>>
java B2B2C Springcloud电子商城系统-Spring Cloud常见问题与总结(四)
查看>>
2017双11技术揭秘—阿里巴巴数据库技术架构演进
查看>>
聊聊字典编码
查看>>
独家 | 史上最权威的BI 趋势分析及产品对比
查看>>