选择Treeviewitem并打开新窗口(WPF) [英] Treeviewitem selected and open new window (WPF)

查看:99
本文介绍了选择Treeviewitem并打开新窗口(WPF)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是WPF的新手,

我将TreeViewControl作为菜单项放在DockPanel的左侧,我从数据库中填充了菜单项,并用TreeViewItem填充了菜单项,这可以正常工作.

现在,我想打开一个相应的表单(WPF Windows表单),该表单将在与该TreeViewItem链接的DockPanel(中心)中打开.

在我的Selected_ChangedRoutedEventArgs中,下面的代码如下:

Hello All,

I am newbie to WPF,

I have TreeViewControl as menu item in DockPanel left hand side and I populate the menu items from my database and fill it up with TreeViewItem''s, which works correctly.

Now I would like to open a corresponding form (WPF Windows form) to be opened in DockPanel (Center) which is linked with that TreeViewItem.

In my RoutedEventArgs of Selected_Changed below is below code:

TreeViewItem selectedItem = (TreeViewItem)MenuTree.SelectedItem;
                if (selectedItem.Tag.ToString() != null)
                {
                    DataRow[] Dr = MnuDs.Tables[0].Select("MenuId=" + selectedItem.Tag.ToString());
                    if (Dr.Length > 0)
                    {
                        if (Dr[0]["FormName"].ToString() != "")
                        {
                            Window frm = (Window)this.GetType().Assembly.CreateInstance("myprojectName." + Dr[0]["FormName"].ToString());
                           if (frm != null)
                            {
                                frm.Show();
                                frm.Focus();
                            }
                        }
                        Dr = null;
                    }
                }


我想对上面的代码问几个问题.

1)这是在WPF中执行的正确方法吗?如果不是,那么想寻找适当的代码.

2)我的对应形式打开时任何被选择,但在(中心那并不开)(而不知在哪里写入代码在中心开),并在单独的窗口中打开.

提前非常感谢您.


I would like to ask few question on above code.

1) Is this the right way to do it in WPF, if not then, would like to seek a proper code.

2) My corresponding form opens when any TreeViewItem is selected , but doesn''t open in DockPanel (center) (rather I do not know where to write the code to open in center) and opens in separate window.

Thank you very much in advance.

推荐答案

嗨.您可以将WindowsFormsHost放置在扩展面板中.当用户选择树形视图项目时,通过反射找到所需的元素(如上所示),然后将其放置在WindowsFormsHost中.我知道这可以在Windows窗体控件中使用,但是我不确定它是否可以在窗口中使用.
Hi. You could place a WindowsFormsHost inside your dockpanel.When the user selects the tree view item, find a desired element via reflection(like you demonstrated above) and place it inside WindowsFormsHost. I know this works with windows form controls but I am not sure that it will work with the window.


这篇关于选择Treeviewitem并打开新窗口(WPF)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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