lightswitch 添加 TreeView 控件

代码片段

<UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"  x:Class="LightSwitchApplication.TreeViewControl.DepartmentTreeViewControl"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:local="clr-namespace:LightSwitchApplication.TreeViewControl"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"mc:Ignorable="d"d:DesignHeight="300" d:DesignWidth="400"><UserControl.Resources><local:EntityCollectionValueConverter x:Key="EntityCollectionValueConverter" /></UserControl.Resources><Grid x:Name="LayoutRoot" Background="White"><StackPanel Orientation="Horizontal"><sdk:TreeView Name="treeViewControl" SelectedItemChanged="treeViewControl_SelectedItemChanged"  ItemsSource="{Binding Screen.DepartmentTree}"><sdk:TreeView.ItemTemplate><sdk:HierarchicalDataTemplate ItemsSource="{Binding Converter={StaticResource EntityCollectionValueConverter}, ConverterParameter=Children}"><StackPanel Orientation="Horizontal"><!--<CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}"/>--><TextBlock Text="{Binding Path=Name, Mode=TwoWay}" Margin="5,0" Width="74" /></StackPanel></sdk:HierarchicalDataTemplate></sdk:TreeView.ItemTemplate></sdk:TreeView></StackPanel></Grid>
</UserControl>

  

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<object> e){var selectItem = (LightSwitchApplication.Department)treeViewControl.SelectedItem;var type1 = selectItem.GetType();var context = (IContentItem)this.DataContext;var screen = context.Screen;var data = (VisualCollection<LightSwitchApplication.Department>)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 tovar entities = new ObservableCollection<IEntityObject>();var temporaryEntites = new List<IEntityObject>();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 threadforeach (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<IDataService> 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<object>(TreeViewItem_SelectedItemChanged);}});}private void TreeViewItem_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> 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 cachingthis.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://www.mzph.cn/news/461388.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

执行jar包,输出信息到文件

有时如果临时需要上项目执行一些脚本或者临时文件&#xff0c;可以将项目达成jar包&#xff0c;去执行执行jar包&#xff1a; java -jar test.jar输出日志到文件&#xff1a;nohup java -jar test.jar > test.txt &也可以执行 .sh脚本项目达成jar包运行&#xff1a;http…

web服务器的简单实现——HTTP权威指南读书心得(七)

我又回来做笔记了~最近懒死了&#xff0c;书虽然看完了&#xff0c;但是一直懒得动笔&#xff0c;这样不行啊&#xff08;﹃&#xff09;口水。还有在这里吐槽下&#xff0c;在围观这本书的时候&#xff0c;一直有一种奇怪的感觉&#xff1a;里面说的有些东西与时代脱节啊.....…

四季星空

内容整理于 http://www.astron.ac.cn/bencandy-50-814-1.htm http://www.360doc.com/content/13/0817/18/1003261_307868525.shtml 注&#xff1a;指的是8点到凌晨时间段的星空&#xff0c;本人习惯面向北方看图。 春季星空&#xff08;3~5月&#xff09; 特征&#xff1…

data怎么给echart传值_通用技术 VUE 子父组件传值

为啥这点东西需要一周时间&#xff1a;1、首先是水平一般&#xff0c;能力有限&#xff0c;前后端都是半吊子&#xff0c;再加上最近有点松劲了&#xff1b;2、由于前期规划问题&#xff0c;在做质量统计的时候&#xff0c;需要做大量的数据整理、统计工作。3、将前端的Echart做…

查看端口是否被占用,以及端口的应用名称

根据进程号查看占用的端口 netstat -anp |grep 进程号查看进程号 ps -ef | grep 应用名称根据端口号查看占用端口的应用 lsof -i :8080转载于:https://www.cnblogs.com/duende99/p/11519643.html

Bad Request (Invalid Hostname)解决方法

当在Windows Server 2003IIS6做Web服务器&#xff0c;出现打开如http://paullevi.oicp.net,出现,Bad Request (Invalid Hostname) 的提示时&#xff0c;更改IIS6的Internet 信息服务管理器的默认网站里的属性->网站->IP地址栏&#xff0c;设置为(全部未分配) &#xff0c…

天文摄影的后期处理

见文&#xff1a;http://space.lamost.org/watch/photography/houqi.htm 主要包含以下三个步骤&#xff1a; 1、调整亮度、对比度&#xff1b; 2、锐化处理&#xff1b; 3、叠加&#xff1b;

android关于socket编程,以聊天为例【转】http://hi.baidu.com/yaoyuanhuajx/item/9b93d7565f315ba9acc857d7...

一步一步android(15)&#xff1a;关于socket编程【以聊天为例】 Android手机的应用&#xff0c;除了它的手机功能之外&#xff0c;另外一个吸引人的地方在于它的开放性&#xff0c;这一点iphone无法比拟&#xff0c;至少iphone太多商业化气息。 如同当年windows95一样&#xff…

交流电的有效值rms值_【电工基础知识:三、正弦交流电的产生】2正弦交流电的三要素...

正弦交流电正弦交流电是随时间按照正弦函数规律变化的电压和电流。由于交流电的大小和方向都是随时间不断变化的&#xff0c;也就是说&#xff0c;每一瞬间电压(电动势)和电流的数值都不相同&#xff0c;所以在分析和计算交流电路时&#xff0c;必须标明它的正方向。一、周期、…

PHP+Ajax点击加载更多列表数据实例

PHPAjax点击加载更多列表数据实例 一款简单实用的PHPAjax点击加载更多列表数据实例&#xff0c;实现原理&#xff1a;通过“更多”按钮向服务端发送Ajax请求&#xff0c;PHP根据分页参数查询将最新的几条记录&#xff0c;数据以JSON形式返回&#xff0c;前台Query解析JSON数据&…

单反使用知识

内容整理于网络 http://academy.fengniao.com/393/3935386_all.html http://dcdv.zol.com.cn/243/2430148_all.html 单反品牌和型号 大部分是佳能、尼康&#xff0c;几乎中低端市场全是这两品牌&#xff0c;另外还有索尼、奥林巴斯、宾得等。对于佳能&#xff0c;一位数D为专…

elementui的css文件没有引入_Python中引入模块详细介绍,使用模块的过程中注意事项教程...

​为此 Python 提供了一个办法&#xff0c;把这些定义存放在文件中&#xff0c;这个文件被称为模块。模块是一个包含所有你定义的函数和变量的文件&#xff0c;其后缀名是.py。模块可以被别的程序引入&#xff0c;以使用该模块中的函数等功能。你也许还想到&#xff0c;如果不同…

【原】git命令行查看全部分支与远程分支不同步问题

git branch -a 查看全部分支 git fetch 重新拉一下分支 转载于:https://www.cnblogs.com/luckyXcc/p/11528000.html

星空摄影入门

https://www.zhihu.com/question/21710281?fromprofile_question_card

猫:君主般的眼神 监视领地。 狗

转载于:https://www.cnblogs.com/imihiroblog/archive/2013/02/04/2891326.html

积累的VC编程小技巧之文件操作

1.删除文件夹 // 删除文件夹及其所有内容void CBaseDoc::RemoveFolder(const CString &strPathName){ CString path strPathName; if (path.Right(1) ! _T("\\")) path _T("\\"); path _T("*.*"); CFileFind ff; B…

Redis分布式锁解决抢购问题

转&#xff1a;https://segmentfault.com/a/1190000011421467 废话不多说&#xff0c;首先分享一个业务场景-抢购。一个典型的高并发问题&#xff0c;所需的最关键字段就是库存&#xff0c;在高并发的情况下每次都去数据库查询显然是不合适的&#xff0c;因此把库存信息存入Red…

Linux进程编程1——与“进程”相关的常识

以下内容源于网络资源的学习与整理&#xff0c;如有侵权请告知删除。 一、进程的概述 进程&#xff0c;是指一个具有独立功能的程序关于某个数据集合的一次可以并发执行的运行活动&#xff0c;是处于活跃状态的计算机程序&#xff0c;是系统进行资源分配和调度的基本单位。进程…

在成长中遇到的挫折事件对你的影响_多种语言环境中成长的宝宝,会影响说话早晚?其实没有想象的复杂...

关于用多种语言抚养孩子的案例比比皆是&#xff0c;但并不是所有的父母都鼓励这样做&#xff0c;他们被告知这会导致孩子混乱和语言延迟&#xff0c;使他们错过机会之窗。以下是最常见的案例&#xff0c;以及把孩子培养成双语者背后的真实故事。误解一、与多种语言一起长大会使…

java道路级别

第一级&#xff1a;神人&#xff0c;天资过人而又是技术狂热者同时还拥有过人的商业头脑&#xff0c;高瞻远瞩&#xff0c;技术过人&#xff0c;大器也。如丁磊&#xff0c;求伯君。 第二级&#xff1a;高人&#xff0c;有天赋&#xff0c;技术过人但没有过人的商业头脑&#x…