C # WPF Multiple Panels in an Application - How To

I'm new to WPF / XAML in C #, I've seen some simple tutorials, etc. But today I am confused, never used to create an interface.

I need to display several forms, an instance of which will look something like this: enter image description here

(NB: I only built it in the WYSIWG way, so the XAML markup is a complete mess, this is for a screenshot. I can't even add the table directly to the grid, oh)

I got data like this for every month at school age, so depending on which class is selected, I want it to output like this (schematic)

(NB: instead of each, CustomWindowInstance

I need my form from the 1st screenshot)

enter image description here

So what is this better and simplified approach for?

+3


source to share


1 answer


EDIT 1: I'll call the XAML from the first screenshot that represents the controls you want to display multiple times, XAML 1 and another one where you want to do it, XAML 2.

-

Almost ORIGINAL: Create a separate user control and move the tag content Window

from XAML 1 into it. You can then show it as many times as you like by placing it <yourUserControlNamespace:YourUserControlClass />

in XAML 2.

To be able to communicate with this control in XAML, for example <yourUserControlNamespace:YourUserControlClass Parameter="SomethingHere" />

, you must implement a named dependency property (preferably the property name in XAML + "Property") in .ParameterProperty

YourUserControlClass.xaml.cs



-

EDIT 2: It is also possible to create a DataTemplate with a parameter DataType={x:Type yourVMNamespace:YourVMClass}

for XAML 1 ViewModel (not View) in XAML 2 or the whole application Resources

. In this case, the ViewModel you are linking will be represented by the content itself DataTemplate

. Later you can write <yourVMNamespace:YourVMClass />

like in the first solution.

This approach allows you to display a rich view of any element, for example, in controls derived from ItemsControl

such as ListBox

, all you have to do is bind a property ListBox

ItemsSource

to a collection of instances YourVMClass

(or specify them manually in XAML).

More precisely, in this case, I will not call the YourVMClass

ViewModel.

+3


source







All Articles