Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
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.
Posted
Comments
Sergey Alexandrovich Kryukov 5-May-14 16:19pm    
If you finally come to understanding that you can write code instead of finding it, you will solve this and many other problems. I cannot understand the problem. A user control is essentially a control, not really different from other ContentControl. Its content is a set of controls, and its absolutely irrelevant of one of the children is also a user control.
—SA
[no name] 5-May-14 19:12pm    
Well I have read this several times and I sure can't figure out what about your homework assignment you are confused about. Why do you need to "find" some source code? Why don't you just write it?

1 solution

Hi Deelll,

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

MainWindow.xaml:

XML
<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>


Code behind:

C#
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();
    }
}


Best Regards,

Shai
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900