主窗口内的C#WPF子窗口 [英] C# WPF Child Windows inside Main Window

查看:733
本文介绍了主窗口内的C#WPF子窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此iv环顾了一下,发现MDI对于WPF已过时,基本上我要做的是在加载时在网格对象中显示特定页面,并且一旦下拉菜单中的菜单项是选择后,网格的内容将从另一页更改为内容(这取决于选择的菜单项).

So iv looked around for a bit and found out that MDI is obselete for WPF, Basically what i am trying to do is show a specific page in a grid object on load, and once a menu item from my drop down menu is selected, the content of the grid will be changed to the content from a different page (this is depending on which menu item is selected).

进入更多细节(也许这会有所帮助).要显示窗口的区域将需要没有边框,标题或最小/关闭按钮等的窗口.仅显示此内容窗口,它将无法调整大小,但会固定,我有一个菜单,正如我之前所说,当单击其他菜单项时,相关窗口应显示在固定区域中.此外,如果在此内容中发生了任何按钮或事件(例如,按钮导致显示其他窗口),则固定区域中的内容应由新窗口的内容替换

To go into more detail (perhaps this will help) The area where the window will be shown will need to have the window with no borders, or titles, or buttons to minimize/close etc.. only showing the content of this window, it won't be resizeable but fixed, i have a menu of which as i said earlier, when a different menu item is clicked, the relevant window should be displayed in the fixed area. Additionally if any buttons or events inside this content that is displayed happen (i.e a button causes a different window to show for example) then the content in the fixed area should be replaced by this new window's content

这是我第一次做这样的事情,从我读到的内容来看,这对于WPF应用程序来说是一件非常棘手的事情,我希望我能得到一些我应该去做的见解或方向.我可以做到这一点.

This is the first time i have done something like this and from what i've read it sounds like this is something very tricky for a WPF application, I hope i can get some sort of insight or direction i should be going so that i can make this possible.

谢谢.

推荐答案

例如,您可以尝试 ChildWindow .

编辑#1:

但是,每当我尝试在Xaml中创建WindowContainer时, 名称空间前缀与"xctk:WindowContainer"有关的问题 如何创建适当的名称空间前缀以使用它?

But whenever i try to create a WindowContainer in the Xaml it has problems with the namespace prefix with "xctk:WindowContainer" so how do i create the appropriate namespace prefix to use it?

您必须添加该命名空间:

You have to add that namespace:

xmlns:xctk=http://schemas.xceed.com/wpf/xaml/toolkit

例如:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <xctk:WindowContainer>
            <xctk:ChildWindow Height="100" Width="250" Left="10" Top="10">
                <TextBlock Text="Hello World ..." />
            </xctk:ChildWindow>
        </xctk:WindowContainer>
    </Grid>
</Window>

编辑#2:

您当然可以更改某些属性(例如):

You can of course change some properties (for example):

<xctk:ChildWindow
                Height="100"
                Width="250" 
                Left="10" 
                Top="10"
                Name="chWindow"
                CloseButtonVisibility="Hidden"
                WindowStyle="None"
                BorderThickness="0">

编辑#3:

是的,所以引用的所有内容仍然给我错误.

Ok yeah, so with everything referenced it is giving me errors still..

尝试简单……创建Wpf应用程序,添加Extended WPF Toolkit 2.4 NuGet包,在MainWindow.xaml中添加上一个代码,在MainWindow.xaml.cs中添加下一个代码:

Try it simple… Create Wpf Application, add Extended WPF Toolkit 2.4 NuGet package, in MainWindow.xaml add previous code and in MainWindow.xaml.cs add next code:

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            this.Loaded += MainWindow_Loaded;
        }

        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            this.chWindow.Show();
        }
    }
}

这篇关于主窗口内的C#WPF子窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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