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 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 控件的更多相关文章
- 在工作表左侧中添加TreeView控件
开发环境基于VSTO:visual studio 2010,VB .Net,excel 2007,文档级别的定制程序. 需求是在sheet的左侧停靠System.Windows.Forms.TreeV ...
- 给C#的treeview控件的部分节点添加checkbox
一.先初始化treeview this.treeView1.CheckBoxes = true; this.treeView1.ShowLines = false; this.treeView1.Dr ...
- 树TreeView控件与DataTable交互添加节点(最高效的方法)
#region "读取树结点从Datatable" /// <summary> /// 读取树结点从Datatable" /// </summary&g ...
- WPF中TreeView控件数据绑定和后台动态添加数据(二)
写在前面:在(一)中,介绍了TreeView控件MVVM模式下数据绑定的方法.在这篇文章中,将总结给节点添加事件的方法,这样说有些不对,总之实现的效果就是点击某个节点,将出现对应于该节点的页面或者数据 ...
- WPF中TreeView控件数据绑定和后台动态添加数据(一)
数据绑定: 更新内容:补充在MVVM模式上的TreeView控件数据绑定的代码. xaml代码: <TreeView Name="syntaxTree" ItemsSourc ...
- TreeView控件使用
treeView1.SelectedNode = treeView1.Nodes[0]; //选中当前treeview控件的根节点为当前节点添加子节点: TreeNode tmp; tmp = n ...
- Win32中TreeView控件的使用方法,类似于资源管理器中文件树形显示方式
首先是头文件,内容如下: #include <tchar.h> #include "..\CommonFiles\CmnHdr.h" #include <Wind ...
- asp TreeView控件的使用
相对于之前发过一个TreeView控件的使用方法 本次利用js操作,页面无刷新,性能提高 Css编码可能时我的模板页样式被继承下来,导致页面变乱,不需要的可以去掉 前台 <style> . ...
- C#TreeView控件遍历文件夹下所有子文件夹以及文件
一直对递归的理解不深刻,有时候觉得很简单,可是用起来总会出错.这里需要在TreeView控件里显示一个文件夹下的所有目录以及文件,毫无意外的需要用到递归. 一开始,想到用递归写一个生成每一个节点(Tr ...
随机推荐
- Verilog HDL小练习
5s内15Hz4个LED闪烁,再两秒熄灭,循环往复. 引入en,可以使得4个LED灯全亮,以及恢复周期变化. module led(clk_27MHZ, en, led1, led2, led3, l ...
- Java SSM 框架相关基础面试题
一.Spring 面试题 1. Spring 在 SSM 中起什么作用? Spring 是轻量级框架,作用是作为 Bean 工厂,用来管理 Bean 的声明周期和框架集成. Spring 的两大核心: ...
- win7启动时怎么自动进入桌面
1.按Win+R组合键,打开“运行”对话框.(Win是键盘下方左右两边的两个印有微软标志的键) 2.Windows XP/2003/2008/2008R2输入"control userpas ...
- 孤岛营救问题 (BFS+状压)
https://loj.ac/problem/6121 BFS + 状压 写过就好想,注意细节debug #include <bits/stdc++.h> #define read rea ...
- sock5协议转换http协议工具polipo使用笔记(Centos7)
一.安装 Shadowsocks使用socks5协议,而终端很多工具目前只支持http和https等协议,所以我们为终端设置Shadowsocks的思路就是将socks5协议转换成http协议,然后为 ...
- Log4J日志整合及配置详解
Log4j有三个主要的组件:Loggers(记录器),Appenders (输出源)和Layouts(布局).这里可简单理解为日志类别,日志要输出的地方和日志以何种形式输出.综合使用这三个组件可以轻松 ...
- cp备份操作时如何忽略指定的目录
需求场景:进行CP拷贝备份的时候,子目录里面的某些大文件或是一些log文件是无需备份的,那么在CP操作时需要忽略掉指定的目录. 案例演示如下:备份data目录,但是不包括里面的share子目录. 先看 ...
- 源码解读Linux的limits.conf文件
目录 目录 1 1. 前言 1 2. PAM 2 3. pam_limits 2 4. limits.conf的由来 3 5. 模块入口函数 4 6. 解析limits.conf 6 7. 生效lim ...
- C++基础笔记(int转string)
int a = 23; stringstream ss; ss << a; string s1 = ss.str(); 头文件需添加#include "sstream"
- 125 open source Big Data architecture papers for data professionals
https://www.linkedin.com/pulse/100-open-source-big-data-architecture-papers-anil-madan