通过主窗口为另一个用户控件创建用户控件实例 [英] Create instance of user control to another user control via main windows

查看:75
本文介绍了通过主窗口为另一个用户控件创建用户控件实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:

点击用户控件usercontrol_menu上的Kassa按钮后,用户控件usercontrol_kassa将显示在主窗口中。



问题:

我很难找到正确的源代码来实现它。最近的源代码位于下方。



我也相信你需要使用控制框架,但我不知道如何在这种情况下使用它。 ( http://www.mindstick.com/Articles/ f3ab29d9-8e26-4b01-a0b8-5b41521f9bfc /?帧%20控制%20in%20WPF [ ^ ])



建议检索主窗口的实例然后在usercontrol_menu的按钮Kassa中创建一个新的usercontrol_kassa实例。



信息:

- usercontrol_menu是三个菜单按钮。

- 主窗口将包含两个用户控件(usercontrol_menu和usercontrol_kassa)。

- 单击Kassa按钮后,您应该启用创建新实例usercontrol_kassa,它应该显示在主窗口内。

- 主Windows,usercontrol_menu和usercontrol_kassa有他们自己的项目我n VS 2013.

Goal:
After clicking on the Kassa button from the user control usercontrol_menu, the user control usercontrol_kassa shall be displayed in the mainwindows.

Problem:
I have difficult to find a correct source code to implement it. The closest source code is located below.

I also believe that you need to use control frame but I don't know how to use it in this context. (http://www.mindstick.com/Articles/f3ab29d9-8e26-4b01-a0b8-5b41521f9bfc/?Frame%20control%20in%20WPF[^])

A suggestion is to retrieve the instance of main window and then create a new instance of usercontrol_kassa inside of usercontrol_menu's button Kassa.

Information:
- usercontrol_menu is menu with three buttons.
- The main windows will contain totally two user control (usercontrol_menu and usercontrol_kassa).
- After you have click the Kassa button you should enable to create a new instance of usercontrol_kassa and it should be displayed inside of mainwindows.
- main Windows, usercontrol_menu and usercontrol_kassa has¨their own project in VS 2013.

推荐答案

您好Deelll,



您只需要使用占位符进行区域管理即可例如:



MainWindow.xaml:



Hi Deelll,

You just need to use region management by placeholders for example:

MainWindow.xaml:

<Window x:Class="WpfApplication10.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="MainWindow" Height="350" Width="525">
    <DockPanel LastChildFill="True">
        <ToolBar DockPanel.Dock="Top">
            <Button Content="UserControl1" Click="Button1_Click" />
            <Button Content="UserControl2" Click="Button2_Click" />
        </ToolBar>
        <ContentPresenter x:Name="workspacePlaceHolder" />
    </DockPanel>
</Window>

< br $> b $ b

代码落后:





Code behind:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void Button1_Click(object sender, RoutedEventArgs e)
    {
        this.workspacePlaceHolder.Content = new UserControl1();
    }

    private void Button2_Click(object sender, RoutedEventArgs e)
    {
        this.workspacePlaceHolder.Content = new UserControl2();
    }
}





最好的问候,



Shai



Best Regards,

Shai


这篇关于通过主窗口为另一个用户控件创建用户控件实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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