如何从UserControl事件更改WPF TabControl的TabItem? [英] How to change TabItem of WPF TabControl from the UserControl Event?

查看:76
本文介绍了如何从UserControl事件更改WPF TabControl的TabItem?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的项目中,即在WPF中,TabControl有4个选项卡。在第4个选项卡上有一个包含DataGrid的UserControl。我想导航tha TabItem 1,即TabIndex 0,当点击DataGrid的行时



之前我的DataGrid直接托管在TabItem 4上而不是UserControl,我可以根据导航TabItem 1这个 [ ^ ]但当我把DataGrid放在UserControl上时无法导航。



请帮帮我...

Hi
In my project i.e in WPF there is TabControl with 4 tab. On the 4th Tab a UserControl that hold a DataGrid. I want to navigate the tha TabItem 1 i.e TabIndex 0 when click on the Row of DataGrid

Before above when my DataGrid is directly hosted on the TabItem 4 not a UserControl, I am able to navigate the TabItem 1 according to This[^] but when I put the DataGrid on the UserControl the not able to navigate.

Please help me...

推荐答案

您需要将usercontrol中的事件冒泡到主窗口。一旦事件被路由,你可以在主窗口中捕获事件,它将像你所描述的那样工作



在上面我的DataGrid直接托管在TabItem 4不是UserControl,我能够导航TabItem 1



希望你能得到这个想法。希望它有所帮助:)
You need to bubble event in usercontrol to the main window. once the event is routed you can catch the event in mainwindow and it will work like the one what you have described

"Before above when my DataGrid is directly hosted on the TabItem 4 not a UserControl, I am able to navigate the TabItem 1 "

Hope you are getting the idea. Hope it helps :)


这篇关于如何从UserControl事件更改WPF TabControl的TabItem?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆