代码片段

<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. apache禁止IP访问网站

    参考资料: http://www.cnblogs.com/zhuangge/archive/2011/04/13/2014892.html 先引用一下上面资料的内容: 用apache搭建的WEB服务器 ...

  2. powershell获取windows子文件夹的大小

    $startFolder = "E:\Migration\" $colItems = (Get-ChildItem $startFolder | Where-Object {$_. ...

  3. mysql的innodb和myisam的区别和应用场景

    1. 区别: (1)事务处理: MyISAM是非事务安全型的,而InnoDB是事务安全型的(支持事务处理等高级处理): (2)锁机制不同: MyISAM是表级锁,而InnoDB是行级锁: (3)sel ...

  4. 简单利用jQuery,让前端开发不再依赖于后端的接口

    前端开发的过程中,我们免不了和后端进行联调,这时候就会出现以下的尴尬场景: 接口没写好,没法做接下来的功能 功能写好了,接口没写好,没法测这个功能 联调了,出了BUG,不知道锅在谁身上,只得陪后端耗时 ...

  5. PHP-循环结构-数组(难)

    今日目标: (1)循环结构 —— do..while.. —— 掌握 (2)循环结构 —— for —— 重点 (3)数组 —— 重点 1.PHP中的循环结构 —— do..while... do: ...

  6. OpenSessionViewFilter

    OpenSessionViewFilter是spring提供的一个针对hibernate的一个支持类,其主要的意思是=在发起一个页面请求的时候打开session,并且保持session直到请求结束,具 ...

  7. ABP框架系列之三十八:(NHibernate-Integration-NHibernate-集成)

    ASP.NET Boilerplate can work with any O/RM framework. It has built-in integration with NHibernate. T ...

  8. Clion pycharm激活码(可使用到2019年2月)

    D87IQPUU3Q-eyJsaWNlbnNlSWQiOiJEODdJUVBVVTNRIiwibGljZW5zZWVOYW1lIjoiTnNzIEltIiwiYXNzaWduZWVOYW1lIjoiI ...

  9. you-get 安装和用法

    以windows为例 安装 从https://github.com/soimort/you-get/releases/latest下载*-full.7z,解压后在cmd中切换至目录下执行you-get ...

  10. Android-Java-静态成员变量&成员变量&局部变量(内存图&回收机制)

    静态成员变量(回收机制) StaticDemo 和 MyDemo package android.java.oop13; class MyDemo { /** * 定义一个静态变量 */ public ...