请问C#的listview嵌套类型如何嵌套

List&int& list = new List&int&();
list.Add(5);
foreach (object obj in list)
MessageBox.Show(obj.GetType().FullName);
static void Main(string[] args)
List&int& list = new List&int& { 1, 2, 3, 4, 5 };
fun(list);
public static void fun(object o)
Type type = o.GetType();
if (type.IsGenericType)//判断是否是泛型
Type[] genericTypes = type.GetGenericArguments();
Console.WriteLine("泛型参数有:");
foreach (Type t in genericTypes)
Console.WriteLine(t.Name);
//想判断这个list的类型 并遍历其中所有元素 怎么做?
if (Array.IndexOf(type.GetInterfaces(), typeof(IEnumerable)) & -1)
IEnumerable en = o as IE
foreach (object obj in en)
Console.WriteLine(obj);
引用 3 楼 bdmh 的回复:
List&int& list = new List&int&();
list.Add(5);
foreach (object obj in list)
MessageBox.Show(obj.GetType().FullName); ……
引用 4 楼 ojlovecd 的回复:
static void Main(string[] args)
List&int& list = new List&int& { 1, 2, 3, 4, 5 };
fun(list);
public static void fun(object……
应该这次初始化List吧List&int& list = new List&int&(new int[] { 1, 2, 3, 4, 5 });
引用 6 楼 advisd 的回复:
应该这次初始化List吧List&int& list = new List&int&(new int[] { 1, 2, 3, 4, 5 });
你还在用C#2.0吧……
引用 4 楼 ojlovecd 的回复:
static void Main(string[] args)
List&int& list = new List&int& { 1, 2, 3, 4, 5 };
fun(list);
public static void fun(object o)
这个是我要的 3Q 跪谢~~膜拜~~ONVIF客户端搜寻设备获取rtsp地址开发笔记(精华篇)_请教怎么删除 嵌套在datalist 中的 gridview 的记录_请教怎么删除unique约束__脚本百事通
稍等,加载中……
^_^请注意,有可能下面的2篇文章才是您想要的内容:
ONVIF客户端搜寻设备获取rtsp地址开发笔记(精华篇)
请教怎么删除 嵌套在datalist 中的 gridview 的记录
请教怎么删除unique约束
ONVIF客户端搜寻设备获取rtsp地址开发笔记(精华篇)
ONVIF客户端搜索设备获取rtsp地址开发笔记(精华篇)
目前ONVIF协议家族设备已占据数字监控行业半壁江山以上,亲,作为开发者的你还在犹豫是否了解下吗?本文介绍了ONVIF客户端从设备搜索,鉴权,能力获取,媒体信息获取,URI地址获取的整套流程。文章只讲述了比较重要或其他博文没有讲述的开发点,详细可以参考文末参考文章。最后,能获得rtsp地址之后,然后去做其他功能比如录像,ptz这些就非常得心应手了。本文出自CSDN-固本培元 ,转载注明出自:。
前言及鸣谢:
感谢guog先生,快活林高先生,onvif全国交流群的的酷夏先生在开发过程中给予的巨大支持,没有你们的帮助开发过程将异常艰难啊。谢谢了!
ONVIF介绍:
ONVIF致力于通过全球性的开放接口标准来推进网络视频在安防市场的应用,这一接口标准将确保不同厂商生产的网络视频产品具有互通性。2008年11月,论坛正式发布了ONVIF第一版规范——ONVIF核心规范1.0。随着视频监控的网络化应用,产业链的分工将越来越细。有些厂商专门做摄像头,有些厂商专门做DVS,有些厂商则可能专门做平台等,然后通过集成商进行集成,提供给最终客户。这种产业合作模式,已经迫切的需要行业提供越来越标准化的接口平台。
流程总览:
本文开发环境:Centos6.4
Gsoap:2.8.16
soap:1.2 onvif:2.4 。 注: 本文提供的参考代码其实网上都可以找到,这里做一个整理,供大家交流学习,共同提高。
搜索:Probe: 发现网络摄像头,获取webserver地址
http://192.168.15.240/onvif/device_service
能力获取:GetCapabilities:获取设备能力文件,从中识别出媒体信息地址URI:
http://192.168.15.240/onvif/Media
媒体信息获取:GetProfiles: 获取媒体信息文件,识别主通道、子通道的视频编码分辨率
RTSP地址获取:GetStreamUri:获取指定通道的流媒体地址
rtsp://192.168.15.240:554/Streaming/Channels/2?transportmode=unicast
Gsoap及开发框架生成:
1.下载Gsoap:地址:http://sourceforge.net/projects/gsoap2/files/gSOAP/
./configure && make && make install
期间可能会有一些报错,自己解决哦。
3.离线或者在线生成onvif.h。如果不需要最新的版本推荐离线方式。笔者使用的是这种方式。
离线文件下载地址:感谢guog先生的共享:
wsdl2h -o onvif.h -c -s -t ./typemap.dat devicemgmt.wsdl media.wsdl event.wsdl display.wsdl deviceio.wsdl imaging.wsdl ptz.wsdl receiver.wsdl recording.wsdl search.wsdl remotediscovery.wsdl replay.wsdl analytics.wsdl analyticsdevice.wsdl actionengine.wsdl accesscontrol.wsdl doorcontrol.wsdl
离线文件在:
http://download.csdn.net/detail/u75143
在线命令:
wsdl2h -o onvif.h -c -s -t ./typemap.dat http://www.onvif.org/onvif/ver10/device/wsdl/devicemgmt.wsdl http://www.onvif.org/onvif/ver10/media/wsdl/media.wsdl http://www.onvif.org/onvif/ver10/event/wsdl/event.wsdl http://www.onvif.org/onvif/ver10/display.wsdl http://www.onvif.org/onvif/ver10/deviceio.wsdl http://www.onvif.org/onvif/ver20/imaging/wsdl/imaging.wsdl http://www.onvif.org/onvif/ver20/ptz/wsdl/ptz.wsdl http://www.onvif.org/onvif/ver10/receiver.wsdl
http://www.onvif.org/onvif/ver10/recording.wsdl http://www.onvif.org/onvif/ver10/search.wsdl http://www.onvif.org/onvif/ver10/network/wsdl/remotediscovery.wsdl http://www.onvif.org/onvif/ver10/replay.wsdl http://www.onvif.org/onvif/ver20/analytics/wsdl/analytics.wsdl http://www.onvif.org/onvif/ver10/analyticsdevice.wsdl http://www.onvif.org/ver10/actionengine.wsdl http://www.onvif.org/ver10/pacs/accesscontrol.wsdl http://www.onvif.org/ver10/pacs/doorcontrol.wsdl
(记得拷贝gsoap的typemap文件至生成目录下,wsdl2h命令需要这个。)
离线命令:
wsdl2h -o onvif.h -c -s -t ./typemap.dat devicemgmt.wsdl media.wsdl event.wsdl display.wsdl deviceio.wsdl imaging.wsdl ptz.wsdl receiver.wsdl recording.wsdl search.wsdl remotediscovery.wsdl replay.wsdl analytics.wsdl analyticsdevice.wsdl actionengine.wsdl accesscontrol.wsdl doorcontrol.wsdl
现在可以开始生成了:如下:
如果直接生成对应C的库文件会发生重复定义错误,可以修改该文件。
wsa5.h(288): **ERROR**: remote method name clash: struct/class 'SOAP_ENV__Fault' already declared at line 274
打开文件gsoap_2.8.16/gsoap-2.8/gsoap/import/ wsa5.h
将277行int SOAP_ENV__Fault修改为int SOAP_ENV__Fault_alex
笔者没有使用这种方法,是将这个结构体直接注释的方式,最后的结果是,都可以使用。
同时上一步生成的onvif.h文件中没有打开wsse.h, 导致最后生成代码中SOAP_ENV__Header 结构体中缺少定义 wsse__Security数据段,无法进行鉴权命令。
即:添加对openssl的支持,在上一步生成的onvif.h中添加(可选)
[cpp] view
随后使用命令生成:
-c onvif.h -x -I/root/Tools/Gsoap/gsoap-2.8/gsoap/import -I/root/Tools/Gsoap/gsoap-2.8/gsoap/ -I/root/Tools/Gsoap/gsoap-2.8/gsoap/custom -I/root/Tools/Gsoap/gsoap-2.8/gsoap/extras -I/root/Tools/Gsoap/gsoap-2.8/gsoap/plugin
到此为止,基于 C 的客户端和服务器的Onvif开发框架及已经搭建完成。
设备搜索原理及编程技巧:
搜索发现的基本原理是:设备上服务器监听239.255.255.250的3702端口。所以,如果要实现跨网段搜索onvif设备需要路由的支持。只要组播数据包能收到,设备就能被搜到。原理是这样。参考代码:
struct soap* NewSoap(struct SOAP_ENV__Header *header,struct soap* soap,
wsdd__ProbeType *req_,
wsdd__ScopesType *sScope_)
soap = soap_new();
if(NULL == soap )
printf("sopa new error\r\n");
return NULL;
soap-&recv_timeout = 5;
soap_set_namespaces(soap, namespaces);
soap_default_SOAP_ENV__Header(soap, header);
char guid_string[100];
uuid_generate(uuid);
uuid_unparse(uuid, guid_string);
header-&wsa__MessageID = guid_
header-&wsa__To = "urn:schemas-xmlsoap-org:ws:2005:04:discovery";
header-&wsa__Action = "http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe";
soap-&header =
soap_default_wsdd__ScopesType(soap, sScope_);
sScope_-&__item = "";
soap_default_wsdd__ProbeType(soap, req_);
req_-&Scopes = sScope_;
req_-&Types = ""; //"dn:NetworkVideoTransmitter";
int i = 0;
result = soap_send___wsdd__Probe(soap, MULTICAST_ADDRESS, NULL, &req);
while(result == SOAP_OK)
result = soap_recv___wsdd__ProbeMatches(soap, &resp);
if(result == SOAP_OK)
if(soap-&error)
printf("soap error 1: %d, %s, %s\n", soap-&error, *soap_faultcode(soap), *soap_faultstring(soap));
result = soap-&
printf("Onvif Device detected *********************************************\r\n");
for(i = 0; i & resp.wsdd__ProbeMatches-&__sizeProbeM i++)
printf("__sizeProbeMatch
: %d\r\n", resp.wsdd__ProbeMatches-&__sizeProbeMatch);
printf("wsa__EndpointReference
: %p\r\n", resp.wsdd__ProbeMatches-&ProbeMatch-&wsa__EndpointReference);
printf("Target EP Address
: %s\r\n", resp.wsdd__ProbeMatches-&ProbeMatch-&wsa__EndpointReference.Address);
printf("Target Type
: %s\r\n", resp.wsdd__ProbeMatches-&ProbeMatch-&Types);
printf("Target Service Address
: %s\r\n", resp.wsdd__ProbeMatches-&ProbeMatch-&XAddrs);
printf("Target Metadata Version : %d\r\n", resp.wsdd__ProbeMatches-&ProbeMatch-&MetadataVersion);
if(resp.wsdd__ProbeMatches-&ProbeMatch-&Scopes)
printf("Target Scopes Address
: %s\r\n", resp.wsdd__ProbeMatches-&ProbeMatch-&Scopes-&__item);
else if (soap-&error)
printf("[%d] soap error 2: %d, %s, %s\n", __LINE__, soap-&error, *soap_faultcode(soap), *soap_faultstring(soap));
result = soap-&
注:搜索到的设备可以加入到自己的设备管理中,这里就不做过多的说明了。
设备鉴权:
鉴权的实现可以很简单也可以很难,这里笔者使用的是gsoap提供的方法:直接调用即可:
soap_wsse_add_UsernameTokenDigest(soap,"user", ONVIF_USER, ONVIF_PASSWORD);
原理也很容易明白其实,就是讲http的soap消息加入对应header中xml的元素而已,然后敏感消息digest MD5加密编码。
所以编译过程中需要使用 lcrypto 也就很正常了。
获取能力:
soap 的http消息通信,参考代码:
void UserGetCapabilities(struct soap *soap ,struct __wsdd__ProbeMatches *resp,
struct _tds__GetCapabilities *capa_req,struct _tds__GetCapabilitiesResponse *capa_resp)
capa_req-&Category = (enum tt__CapabilityCategory *)soap_malloc(soap, sizeof(int));
capa_req-&__sizeCategory = 1;
*(capa_req-&Category) = (enum tt__CapabilityCategory)(tt__CapabilityCategory__Media);
capa_resp-&Capabilities = (struct tt__Capabilities*)soap_malloc(soap,sizeof(struct tt__Capabilities)) ;
soap_wsse_add_UsernameTokenDigest(soap,"user", ONVIF_USER, ONVIF_PASSWORD);
printf("\n--------------------Now Gettting Capabilities NOW --------------------\n\n");
int result = soap_call___tds__GetCapabilities(soap, resp-&wsdd__ProbeMatches-&ProbeMatch-&XAddrs, NULL, capa_req, capa_resp);
if (soap-&error)
printf("[%s][%d]---&&& soap error: %d, %s, %s\n", __func__, __LINE__, soap-&error, *soap_faultcode(soap), *soap_faultstring(soap));
int retval = soap-&
exit(-1) ;
printf(" \n--------------------GetCapabilities
OK! result=%d--------------\n \n",result);
if(capa_resp-&Capabilities==NULL)
printf(" GetCapabilities
result=%d \n",result);
printf(" Media-&XAddr=%s \n", capa_resp-&Capabilities-&Media-&XAddr);
获取媒体信息Profile:
soap 的http消息通信,参考代码:
void UserGetProfiles(struct soap *soap,struct _trt__GetProfiles *trt__GetProfiles,
struct _trt__GetProfilesResponse *trt__GetProfilesResponse ,struct _tds__GetCapabilitiesResponse *capa_resp)
int result=0 ;
printf("\n-------------------Getting Onvif Devices Profiles--------------\n\n");
soap_wsse_add_UsernameTokenDigest(soap,"user", ONVIF_USER, ONVIF_PASSWORD);
result = soap_call___trt__GetProfiles(soap, capa_resp-&Capabilities-&Media-&XAddr, NULL, trt__GetProfiles, trt__GetProfilesResponse);
if (result==-1)
//NOTE: it may be regular if result isn't SOAP_OK.Because some attributes aren't supported by server.
//any question email
printf("soap error: %d, %s, %s\n", soap-&error, *soap_faultcode(soap), *soap_faultstring(soap));
result = soap-&
printf("\n-------------------Profiles Get OK--------------\n\n");
if(trt__GetProfilesResponse-&Profiles!=NULL)
if(trt__GetProfilesResponse-&Profiles-&Name!=NULL){
printf("Profiles Name:%s
\n",trt__GetProfilesResponse-&Profiles-&Name);
if(trt__GetProfilesResponse-&Profiles-&token!=NULL){
printf("Profiles Taken:%s\n",trt__GetProfilesResponse-&Profiles-&token);
printf("Profiles Get inner Error\n");
printf("Profiles Get Procedure over\n");
获取RTSP的URI:
soap 的http消息通信,参考代码:
void UserGetUri(struct soap *soap,struct _trt__GetStreamUri *trt__GetStreamUri,struct _trt__GetStreamUriResponse *trt__GetStreamUriResponse,
struct _trt__GetProfilesResponse *trt__GetProfilesResponse,struct _tds__GetCapabilitiesResponse *capa_resp)
int result=0 ;
trt__GetStreamUri-&StreamSetup = (struct tt__StreamSetup*)soap_malloc(soap,sizeof(struct tt__StreamSetup));//初始化,分配空间
trt__GetStreamUri-&StreamSetup-&Stream = 0;//stream type
trt__GetStreamUri-&StreamSetup-&Transport = (struct tt__Transport *)soap_malloc(soap, sizeof(struct tt__Transport));//初始化,分配空间
trt__GetStreamUri-&StreamSetup-&Transport-&Protocol = 0;
trt__GetStreamUri-&StreamSetup-&Transport-&Tunnel = 0;
trt__GetStreamUri-&StreamSetup-&__size = 1;
trt__GetStreamUri-&StreamSetup-&__any = NULL;
trt__GetStreamUri-&StreamSetup-&__anyAttribute =NULL;
trt__GetStreamUri-&ProfileToken = trt__GetProfilesResponse-&Profiles-&
printf("\n\n---------------Getting Uri----------------\n\n");
soap_wsse_add_UsernameTokenDigest(soap,"user", ONVIF_USER, ONVIF_PASSWORD);
soap_call___trt__GetStreamUri(soap, capa_resp-&Capabilities-&Media-&XAddr, NULL, trt__GetStreamUri, trt__GetStreamUriResponse);
if (soap-&error) {
printf("soap error: %d, %s, %s\n", soap-&error, *soap_faultcode(soap), *soap_faultstring(soap));
result = soap-&
printf("!!!!NOTE: RTSP Addr Get Done is :%s \n",trt__GetStreamUriResponse-&MediaUri-&Uri);
最后贴一个终端截图:
开发注意事项:(必读)
soap通信的命名空间如果错误则不能检索到设备:编译好的wsdd.nsmap文件需要修改命名空间,如下:
如果要正常开发,被检索到,或者发现其他设备需要nsmap修改如下:1.1换1.2
以下命名空间表示SOAP1.1版本:
{"SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/", "http://www.w3.org/*/soap-envelope", NULL},
{"SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/", "http://www.w3.org/*/soap-encoding", NULL}, //1.1
以下命名空间表示SOAP1.2版本:
{"SOAP-ENV", "http://www.w3.org/2003/05/soap-envelope", "http://schemas.xmlsoap.org/soap/envelope/", NULL},
{"SOAP-ENC", "http://www.w3.org/2003/05/soap-encoding", "http://schemas.xmlsoap.org/soap/encoding/", NULL},
调试技巧:
fsend/ frecv 打印出发送和接收到的报文。使用xml编辑器分析。当然也可以直接用浏览器看。
1、打开onvif调试开关,以便让onvif打印一些可用的调试信息。
在Makefile中添加调试宏定义如: CC = gcc -DDEBUG
2、打开调试宏后,默认在程序运行的目录产生三个文件:
RECV.log是onvif接收到的SOAP数据,没接收一条,都会在RECV.log中记录
SENT.log是onvif发送出去的SOAP数据,没发送一套,也会在SENT.log中生成记录
最后是TEST.log,如果说RECV和SENT可以用wireshark工具抓包代替,那么TEST.log是谁也替代不了的,TEST.log记录了onvif的实时的工作状态。
尤其当出现segmentation fault错误,TEST.log就成了唯一一个能够定位到具体内存出错的地方了。
SOAP_TYPE返回soap-&error=4的错误说明
关于数据正确(抓包可收到数据),但soap返回错误,为4 及 SOAP_TYPE 的问题:
GetCapabilities的过程错误时。
多次调试后得出结论,是tt__CapabilityCategory 的设置问题,有的设备不具备全部功能,而请求全部或请求没有的功能就可能造成这种问题,推荐写5(tt__CapabilityCategory__Media)
这是大多数设置有的能力,而且最常用。
GetProfile时错误:
其实数据在抓包过程中也能完全抓到,多次调试后,发现结构体需要的Name以及token关键字被赋值。其他的没有,说明本点返回与服务器的支持性有很大关系。及,开发过程中需要对应自己的需求,根据实际的需要和返回错误,读取返回结构体数据。
ONVIFDEVICEMANAGER下载地址:
/share/link?shareid=&uk=&fid=
ONVIFTESTTOOL下载地址:
/soft/66448.html
官网开发者向导资料下载地址:
http://www.onvif.org/Resources/WhitePapers.aspx
参考文章:
onvif规范的实现:使用gSOAP创建SOAP调用实例
http://blog.csdn.net/ghostyu/article/details/8162280
Onvif开发之服务端成功对接Rtsp视频流篇
http://blog.csdn.net/max_min_go/article/details/
linux设备上的Onvif 实现10:获取支持通道的RTSP地址
http://gaohtao./blog/static//
Onvif开发之客户端鉴权获取参数篇
http://blog.csdn.net/max_min_go/article/details/
ONVIF协议开发资源
http://www.csdn.net/tag/onvif%5E5%2F%5AE%2525AE
onvif开发之设备发现功能的实现
http://blog.csdn.net/love_xjhu/article/details/
Linux设备上的Onvif实现16:实现Onvif鉴权
http://blog.csdn.net/u/article/details/
Onvif开发之Linux下gsoap的使用及移植
http://blog.csdn.net/love_xjhu/article/details/9772361
onvif开发总结
http://blog.csdn.net/zsl/article/details/8971143
代码框架生成之Onvif开发
http://www.yc-edu.org/C__peixun/6655.html
linux设备上的Onvif 实现4:成功编译gsoap 2.8.15
http://blog.csdn.net/u/article/details/
onvif规范的实现:onvif开发常用调试方法 和常见的segmentation
http://blog.csdn.net/ghostyu/article/details/8432760
linux设备上的Onvif 实现6:获取摄像头的流媒体地址完整流程
http://blog.csdn.net/u/article/details/
SOAP 错误代码表
/link?url=rujSmnpjBxjS3mGZrejoVVOShcPu_5Wu_9RKrQ6qWCB12xrZUvVoFkYRepLu0y6oTk6-bB5AnJ_7KxF6s8rXcb1BFko6DbBpXg0_7G0D7cu
linux设备上的Onvif 实现8:编写媒体信息获取程序
http://blog.csdn.net/u/article/details/
请教怎么删除 嵌套在datalist 中的 gridview 的记录
请问如何删除 嵌套在datalist 中的 gridview 的记录激发删除命令是写在gridview
中的RowDeleting里的
每次点删除都是删除datalist中,第一项的gridview中的记录
问题就是无法获取删除的是哪一项gridview
请问大家有什么方法可以解决吗
数据的显示没有问题------解决方案--------------------protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
GridView GridView1 = sender as GridV
//然后可以用GridView1.DataKeys[e.RowIndex].Value.ToString()得到主键列
请教怎么删除unique约束
请问如何删除unique约束建了一个unique 约束 uk_chinese但是删不掉,提示索引 uk_chinese 失败我又去删uk_chinese 的索引,但是索引也删不掉,请问如何删除------解决方案--------------------SQL code
alter table tb drop constraint uk_chinese
------解决方案--------------------
建了一个unique 约束 uk_chinese但是删不掉,提示索引 uk_chinese 失败我又去删uk_chinese 的索引,但是索引也删不掉,请问如何删除
如果您想提高自己的技术水平,欢迎加入本站官方1号QQ群:&&,&&2号QQ群:,在群里结识技术精英和交流技术^_^
本站联系邮箱:帐号:密码:下次自动登录{url:/nForum/slist.json?uid=guest&root=list-section}{url:/nForum/nlist.json?uid=guest&root=list-section}
贴数:2&分页:紫色隐者·敕封 74式发信人: giogio (紫色隐者·敕封 74式), 信区: DotNET
标&&题: [问题][WPF]嵌套ListBox,如何让内层的ListItem被选中时触发外
发信站: 水木社区 (Mon May 21 16:20:29 2012), 站内 && ft,直接按回车,发表空文章了。 && xaml代码: && &Window x:Class="WpfSandBox.View.TestWindow" &&&&&&&& xmlns="/winfx/2006/xaml/presentation" &&&&&&&& xmlns:x="/winfx/2006/xaml" &&&&&&&& Title="TestWindow" Height="300" Width="624"& &&&& &Window.Resources& &&&&&& &DataTemplate x:Uid="DataTemplate_1" x:Key="VisualDataTemplate" DataType="Data"& &&&&&&&& &Grid x:Uid="Grid_1"& &&&&&&&&&& &Grid.RowDefinitions& &&&&&&&&&&&& &RowDefinition x:Uid="RowDefinition_1" Height="1*" /& &&&&&&&&&&&& &RowDefinition x:Uid="RowDefinition_2" Height="1*"/& &&&&&&&&&&&& &RowDefinition x:Uid="RowDefinition_3" Height="auto" /& &&&&&&&&&& &/Grid.RowDefinitions& &&&&&&&&&& &ListBox&&&&&&&&&&&&&&&& x:Uid="_singleTextList"&&&&&&&&&&&&&&&& Name="_singleTextList"&&&&&&&&&&&&&&&& ItemsSource="{Binding Path=SubDatas, Mode=OneWay}" &&&&&&&&&&&&&& IsSynchronizedWithCurrentItem="True" &&&&&&&&&&&&&& Grid.Row="0"&&&&&&&&&&&&&&&& ScrollViewer.HorizontalScrollBarVisibility="Disabled" &&&&&&&&&&&&&& Tag="{Binding}" &&&&&&&&&&&&&& SelectedIndex="-1"& &&&&&&&&&&&& &ListBox.ItemTemplate& &&&&&&&&&&&&&& &DataTemplate x:Uid="DataTemplate_2"& &&&&&&&&&&&&&& &TextBlock&&&&&&&&&&&&&&&&&&&&x:Uid="_subDataSingleText"&&&&&&&&&&&&&&&&&&&&Tag="{Binding Path=ID}"&&&&&&&&&&&&&&&&&&&&Text="{Binding Path=SingleText, Mode=OneWay}" /& &&&&&&&&&&&&&& &/DataTemplate& &&&&&&&&&&&& &/ListBox.ItemTemplate& &&&&&&&&&& &/ListBox& &&&&&&&&&&&& &ListBox&&&&&&&&&&&&&&&& x:Uid="_multiTextList" &&&&&&&&&&&&&& Name="_multiTextList"&&&&&&&&&&&&&&&& ItemsSource="{Binding Path=SubDatas, Mode=OneWay}" &&&&&&&&&&&&&& Grid.Row="1" &&&&&&&&&&&&&& ScrollViewer.HorizontalScrollBarVisibility="Disabled" &&&&&&&&&&&&&& SelectedIndex="-1" &&&&&&&&&&&&&& IsSynchronizedWithCurrentItem="True" &&&&&&&&&&&&&& Tag="{Binding Path=Tag}"& &&&&&&&&&&&& &ListBox.ItemTemplate& &&&&&&&&&&&&&& &DataTemplate x:Uid="DataTemplate_3"& &&&&&&&&&&&&&&&& &ListBox&&&&&&&&&&&&&&&&&&&& x:Uid="_multiTextItem" &&&&&&&&&&&&&&&&&& Name="_multiTextItem"&&&&&&&&&&&&&&&&&&&& ItemsSource="{Binding Path=MultiText, Mode=OneWay}" &&&&&&&&&&&&&&&&&& Grid.Row="1" &&&&&&&&&&&&&&&&&& ScrollViewer.HorizontalScrollBarVisibility="Disabled" &&&&&&&&&&&&&&&&&& IsSynchronizedWithCurrentItem="True"&&&&&&&&&&&&&&&&&&&& SelectedIndex="-1"& &&&&&&&&&&&&&&&& &/ListBox& &&&&&&&&&&&&&& &/DataTemplate& &&&&&&&&&&&& &/ListBox.ItemTemplate& &&&&&&&&&& &/ListBox& &&&&&&&& &/Grid& &&&& &/DataTemplate& && &/Window.Resources& &&&& &Grid& &&&& &Grid.RowDefinitions& &&&&&& &RowDefinition Height="1*" /& &&&&&& &RowDefinition Height="4*"/& &&&&&& &RowDefinition Height="auto" /& &&&& &/Grid.RowDefinitions& &&&& &TextBox x:Name="selectedID" Grid.Row="0"&ABCD&/TextBox& &&&& &ScrollViewer &&&&&& Grid.Row="1" &&&&&&&&&&&& x:Uid="ScrollViewer_1" HorizontalScrollBarVisibility="Disabled" &&&&&&&&&&&& VerticalScrollBarVisibility="Auto"& &&&&&& &ItemsControl &&&&&&&&&&&&&& x:Uid="_itemsControl"&&&&&&&&&&&&&&&& x:Name="_itemsControl" &&&&&&&&&&&&&& ItemTemplate="{StaticResource VisualDataTemplate}" &&&&&&&&&&&&&& ItemsSource="{Binding Path=Datas}"& &&&&&&&& &ItemsControl.Style& &&&&&&&&&& &Style x:Uid="Style_2" TargetType="ItemsControl"& &&&&&&&&&&&& &Setter x:Uid="Setter_6" Property="Template"& &&&&&&&&&&&&&& &Setter.Value& &&&&&&&&&&&&&&&& &ControlTemplate x:Uid="ControlTemplate_1" TargetType="ItemsControl"& &&&&&&&&&&&&&&&&&& &ItemsPresenter x:Uid="ItemsPresenter_1"/& &&&&&&&&&&&&&&&& &/ControlTemplate& &&&&&&&&&&&&&& &/Setter.Value& &&&&&&&&&&&& &/Setter& &&&&&&&&&&&& &Setter x:Uid="Setter_7" Property="ItemsPanel"& &&&&&&&&&&&&&& &Setter.Value& &&&&&&&&&&&&&&&& &ItemsPanelTemplate x:Uid="ItemsPanelTemplate_3"& &&&&&&&&&&&&&&&&&& &StackPanel x:Uid="StackPanel_1"&&/StackPanel& &&&&&&&&&&&&&&&& &/ItemsPanelTemplate& &&&&&&&&&&&&&& &/Setter.Value& &&&&&&&&&&&& &/Setter& &&&&&&&&&& &/Style& &&&&&&&& &/ItemsControl.Style& &&&&&& &/ItemsControl& &&&& &/ScrollViewer& && &/Grid&
&/Window& && 用到的数据类型: && class Data
{ &&&& public ObservableCollection&SubData& SubDatas { }
} && class SubData
{ &&&& public int ID { } &&&&&& public string SingleText { } &&&& public string[] MultiText { }
} && 显示的时候上面的ListBox是各个SubData的SingleText,下面是各个SubData里面的MultiText的ListBox。
现在在上面ListBox选择的时候可以出发ListBox的SelectionChanged事件。
想在下面做到选择某内层ListItem的时候触发外层ListBox的SelectionChanged事件。 && 该怎么做呢? &&&&&& -- && 樱桃神斧&&华盛顿
引雷飞鸢&&范克林
※ 修改:·giogio 于 May 21 16:39:33 2012 修改本文·[FROM: 207.46.92.*]
※ 来源:·水木社区 ·[FROM: 207.46.92.*]
紫色隐者·敕封 74式发信人: giogio (紫色隐者·敕封 74式), 信区: DotNET
标&&题: Re: [问题][WPF]嵌套ListBox,如何让内层的ListItem被选中时触发
发信站: 水木社区 (Mon May 21 19:00:19 2012), 站内 && 啊,原来是DataTemplate的问题……
解决如下: &&
Very well then. One more question like that and I'll find someone else to relate my memoirs to. And you will be feeding the shoggoth. &&&& ※ 来源:·水木社区 ·[FROM: 207.46.92.*]
文章数:2&分页:

我要回帖

更多关于 excel if嵌套 的文章

 

随机推荐