代码片段

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

  

 

lightswitch 添加 TreeView 控件的更多相关文章

  1. 在工作表左侧中添加TreeView控件

    开发环境基于VSTO:visual studio 2010,VB .Net,excel 2007,文档级别的定制程序. 需求是在sheet的左侧停靠System.Windows.Forms.TreeV ...

  2. 给C#的treeview控件的部分节点添加checkbox

    一.先初始化treeview this.treeView1.CheckBoxes = true; this.treeView1.ShowLines = false; this.treeView1.Dr ...

  3. 树TreeView控件与DataTable交互添加节点(最高效的方法)

    #region "读取树结点从Datatable" /// <summary> /// 读取树结点从Datatable" /// </summary&g ...

  4. WPF中TreeView控件数据绑定和后台动态添加数据(二)

    写在前面:在(一)中,介绍了TreeView控件MVVM模式下数据绑定的方法.在这篇文章中,将总结给节点添加事件的方法,这样说有些不对,总之实现的效果就是点击某个节点,将出现对应于该节点的页面或者数据 ...

  5. WPF中TreeView控件数据绑定和后台动态添加数据(一)

    数据绑定: 更新内容:补充在MVVM模式上的TreeView控件数据绑定的代码. xaml代码: <TreeView Name="syntaxTree" ItemsSourc ...

  6. TreeView控件使用

    treeView1.SelectedNode = treeView1.Nodes[0];  //选中当前treeview控件的根节点为当前节点添加子节点:  TreeNode tmp; tmp = n ...

  7. Win32中TreeView控件的使用方法,类似于资源管理器中文件树形显示方式

    首先是头文件,内容如下: #include <tchar.h> #include "..\CommonFiles\CmnHdr.h" #include <Wind ...

  8. asp TreeView控件的使用

    相对于之前发过一个TreeView控件的使用方法 本次利用js操作,页面无刷新,性能提高 Css编码可能时我的模板页样式被继承下来,导致页面变乱,不需要的可以去掉 前台 <style> . ...

  9. C#TreeView控件遍历文件夹下所有子文件夹以及文件

    一直对递归的理解不深刻,有时候觉得很简单,可是用起来总会出错.这里需要在TreeView控件里显示一个文件夹下的所有目录以及文件,毫无意外的需要用到递归. 一开始,想到用递归写一个生成每一个节点(Tr ...

随机推荐

  1. SPARK安装一:Windows下VirtualBox安装CentOS

    一.虚拟机安装 重点是网络设置,参见:https://www.linuxidc.com/Linux/2018-04/151924.htm 本文用三台2核4g虚拟机做集群,虚拟机安装centos7,如下 ...

  2. 基于akka-http搭建restfull框架

    1.scala开发环境介绍 2.scala插件的demo模板介绍 3.akka-http提供demo研究 4.添加路由机制解析 package org.netsharp.rest import akk ...

  3. SQL中GROUP BY语句与HAVING语句的使用

    GROUP BY语句,经过研究和练习,终于明白如何使用了,在此记录一下同时添加了一个自己举的小例子,通过写这篇文章来加深下自己学习的效果,还能和大家分享下,同时也方便以后查阅,一举多得 一.GROUP ...

  4. 谷歌发布了 T2T(Tensor2Tensor)深度学习开源系统

    谷歌开源T2T模型库,深度学习系统进入模块化时代! 谷歌大脑颠覆深度学习混乱现状,要用单一模型学会多项任务 https://github.com/tensorflow/models https://g ...

  5. SAS对数据变量的处理

    SAS对数据变量的处理 在使用DATA步基于已经存在的数据集生成新数据集时,可以指定在新数据集中不需要包含的变量而仅读取其他变量,或者指定仅需要在 新数据集中包含的变量.该功能可以通过DATA步中的S ...

  6. linux mysql 5.7.25 安裝

    1.下载 https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz 2.解压 tar ...

  7. PowerShell工作流学习-1-嵌套工作流和嵌套函数

    关键点: a)嵌套深度没有任何语法限制,但是嵌套三个层次的工作流不支持任何通用参数,包括工作流通用参数 b)嵌套工作流可以调用当前范围和任何父范围内的工作流和函数 c)工作流不允许递归调用,脚本和函数 ...

  8. .NET Core微服务之路:文章系列和内容索引汇总 (v0.52)

    微服务架构,对于从事JAVA架构的童鞋来说,早已不是什么新鲜的事儿,他们有鼎鼎大名的Spring Cloud这样的全家桶框架支撑,包含微服务核心组件如 1. Eureka:实现服务注册与发现. 2. ...

  9. C# MVC微信扫码支付

    项目需求:学校学生网上缴费项目,刚来公司实习网上百度了各种资料,感谢很多大神避免了很多大坑. 本次扫码支付为:电脑生成二维码,手机微信扫码进行付款.建议开发前下载官方demo熟悉及后续有用到里面代码: ...

  10. ReactNative 深拷贝

    1: 导入 import _ from 'lodash' 2: _.cloneDeep(obj)