WPF application - UI composability

neegotiator

Golden Member
Jan 19, 2006
1,117
1
0
I've been tasked with creating a Windows desktop application for data entry. I'm new to WPF, so apologies if unclear.

This will be just a single window, but there will be a decent amount of stuff entered where I'd like to separate out into multiple decoupled views rather than having one big XAML file. So in main window, there would be a section A with pertaining user controls, below that section B, etc... Each section would have their own views, that would be embedded into main Window. I've glanced over using Prism framework to define regions within window, but was wondering how to go about embedding views using vanilla WPF? Tried Google, but maybe just not using right terms. Thanks in advance!
 

neegotiator

Golden Member
Jan 19, 2006
1,117
1
0
Thanks brandon. I get data binding, MVVM and separation of concerns, but I'm specifically asking about View portion. I glanced through the articles and didn't see an example (unless I missed it).

If I have multiple Views with their respective ViewModels and want to display contents of those Views as children inside a Panel within a "main" View, what does that look like in XAML? For example, if I were building application to enter in resume info. In main View I have a StackPanel. The 1st child of StackPanel would reference PersonalInfoView.xaml, the 2nd child would reference JobHistoryView.xaml, 3rd child would reference EducationHistoryView.xaml, etc...
 

brandonb

Diamond Member
Oct 17, 2006
3,731
2
0
This is what I do. I'm not sure if its the best thing to do or not, and someone else might have a better suggestion.

1) I learned very quickly to avoid XAML entirely. I don't use it at all. I've delete the XAML in all my applications. I use the Application Startup Event, I call a class.

2) That class will create the Window, and then invoke the ViewModel (another class in a .DLL) which is specified by a command line argument to the program.

3) That ViewModel Implements an interface that I created. One of the methods is Initialize which returns the parent/child relationship of what it represents. So the View Model specifies the View it needs. (Everything in Xaml can be made in code using System.Windows.Controls namespace. Most objects will have a Child or Children property)

4) When the host project gets the interface from the View Model. It generates on the screen what it needs, creates the data bindings so everything links back to the ViewModel. This is completely dynamic, nothing is known ahead of time in the host project, and changes per ViewModel.

5) The ViewModel can also instruct the app (through Events) to "CreateView", to get the host project to launch another ViewModel DLL. Which of course will Initialize, generate it's own view, which the App will link up to that. But the ViewModels are basically separate from one another even though I've created a communication model where they can talk to one another through a message pump.

---

I'm going to say right now. It took me a long time to figure that out as I had no idea what I was doing before I started. Other than "Hey. I want to section off my code." So I probably rewrote Prism and wasn't even aware of it, but I learned a ton in the process.

---

As far as getting Xamls to launch other Xamls in part of its screen, I have no idea. I'm not all that strong with Xaml since I probably had the same question as you 5+ years ago and determined you couldn't, and dropped Xaml completely.
 
Last edited:

Hmongkeysauce

Senior member
Jun 8, 2005
360
0
76
What you can do is have a ListBox of your Views defined in your main view. The item source for the ListBox would be a list of your viewmodels that is defined in your main viewmodel. In the template of your ListBox, bind the visibility of the view to a Visibility property in the viewmodel. As the user clicks "Next" or "Previous" (I'm assuming that is how users will navigate between views), your Main viewmodel will then toggle the visibility of the viewmodels to true or false.
 

neegotiator

Golden Member
Jan 19, 2006
1,117
1
0
Thanks guys for the replies, think found what I was looking for. Essentially needed ContentControl tag, and within point DataTemplate tag to the view I want. So now, I can break off my main Window into manageable chunks of related data inputs.

Code:
<ContentControl Grid.Row="1" Grid.Column="0" Content="{Binding}">
    <ContentControl.ContentTemplate>
        <DataTemplate>
            <v:MyView></v:MyView>
        </DataTemplate>
    </ContentControl.ContentTemplate>
</ContentControl>

Thanks brandon, yeah when I initially looked at XAML, I thought cool. I have a declarative way, like HTML, to declare visual components, encapsulate styles, etc... I'll probably still go down that for now, but will definitely take a look at your suggestion. Above and other things (seem to get intermittent bugs where names in clr-namespace don't get recognized) make this not as smooth an experience as I had hoped.

Thanks again guys.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |