0

I have an assignment where I have to show two instances of the same class in two different windows within same WPF window. Is there any ways to achieve this? I am very new to WPF so its bit tough to handle. How to design the GUI part, which panel to use and how to assign the class to respective windwow in code-behind.

I have tried with DockPanel, code is below

<Window x:Class="Layout"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"                                       
        mc:Ignorable="d"
        Title="Layout" Height="450" Width="800">
    <Grid x:Name="grd_main">

        <DockPanel x:Name="dockpanel1"  HorizontalAlignment="Left" Height="194" LastChildFill="False" Margin="10,10,0,0" VerticalAlignment="Top" Width="772">
            <Window Name="windows1">
            </Window>
        </DockPanel>

        <DockPanel x:Name="dockpanel2" HorizontalAlignment="Left" Height="200" LastChildFill="False" Margin="10,209,0,0" VerticalAlignment="Top" Width="772">
            <Window Name="windows2"></Window>
        </DockPanel>
    </Grid>

</Window>

But dont know how to assign class instance to window in code-behind. I would like to know the best approach to achieve, provide me with some example code snippet. Thanks in advance.

Sam
  • 61
  • 1
  • 7
  • 1
    You cannot add window into other controls... Use a UserControl instead – Nawed Nabi Zada May 13 '19 at 09:23
  • If you really need them be inner windows then check this guide: https://www.codeproject.com/Articles/22927/Multiple-Window-Interface-for-WPF. Otherwise, UserControl is your best friend. – El Barrent May 13 '19 at 10:44
  • The "within the same window" part of your requirement should be clarified. If it means click a button and show a new instance of a window then that makes some sense. If it means hosted inside the parent window somehow then that makes very little sense. That is not an assignment suitable for someone new to wpf. Please reconsider, review and edit to clarify your posted question. – Andy May 13 '19 at 11:03
  • Thanks for the reply. I will try to implement using UserControl. @Andy actually I have two types of output depends on the parameter, one is data in datagrid and other is different. So both I have to show adjacently in the same window, thats why I have end up with this requirement. Is there any other better approach or better GUI format of display. Sometimes show two windows or three maximum 4. – Sam May 13 '19 at 13:30
  • You need to show some stuff adjacent on one window. OK. Got that. One window, grid, two columns. Put something in each. Then there's "Sometimes show two windows or three maximum 4". Makes no sense. What's that got to do with anything? – Andy May 13 '19 at 14:24
  • You could also use a `Page`. I find i like them for layout over a usercontrol. easy to swap within a `Frame` – Ginger Ninja May 13 '19 at 14:28
  • Thanks for the reply..@Andy its not fixed to have only two screens, in future it could be divided into 3 to show 3 screens or 4. Anyhow 4 would be the maximum. That is what I mean. – Sam May 13 '19 at 15:02
  • Hi Everyone, I have tried with the UserControl in Grid for multiple views in same window, the GUI Part is ready. Thank you all for the guidance and input. Now I have one usercontrol which has Datagrid, but I dont have any idea of how to bind the events like AutoGeneratedColumn. How can i make it so generic for all the Datagrid. Is is possible?? Absolutely no idea? Any suggestions are highly appreciated. – Sam May 16 '19 at 13:28

0 Answers0