Reputation: 51958
I'd like to have a reusable window in my desktop application that could potentially have different xamls "injected" into it. Because I'd like all my windows to have the same look (I have a nifty title bar and close button, etc)
For example, I'd like to have a messagebox (ok/cancel/string) used in it. I'd like it to be used to host a form, etc.
I currently have:
MyWindow.xaml/cs (is a Window)
MyMessageBox.xaml/cs (is a User Control)
MyForm.xaml/cs (is a User Control)
So what is the best way to implement this. Do I just put a ContentPresenter in MyWindow and then somehow "inject" the other xamls into it? Do I need the other controls to inherit something from the base window?
I'm just looking for some feedback on the best way to go about what I'm trying to do. Thanks
Upvotes: 3
Views: 1571
Reputation: 581
I agree with with Henk Holterman's answer. I've just written a small 'framework' for WPF applications of this sort. I use an inteface on the 'content' pages to define common functionality for the code-behind; I have a generic page template that I use to give me a caption block, close button, etc.
I'd avoid visual inheritance with WPF unless you absolutely need it - it can be rather tricky to get right.
Upvotes: 1
Reputation: 74560
You should seriously consider using Prism (developed by Microsoft, coming out of the Patterns & Practices group) for this; it was built to handle exactly these scenarios, providing tools for composing UIs.
Upvotes: 0
Reputation: 273581
A simple approach would be a Window with a Frame, and then load pages into that Frame on demand.
Upvotes: 2