WPF modularity question(s) -- hot swapping
-
I have a couple questions for WPF that I hope have simple answers: Suppose I want to make my interface modular and abstract, so that I don't need to group everything into a single xaml file. What is the simplest and most efficient way to dynamically swap out pieces of a xaml interface? In WinForms this could be done simply by using panels, and changing the child control(s) of the panel. Is there a similar idea in WPF? And relatedly, what's the best way to define xaml fragments that aren't entire windows themselves. User controls? Pages? And finally (bonus, unrelated question): is WPF layout strictly grid/hierarchically-based? If I want a fragment such as the above to appear floating over the other elements in a window/grid, can i do that without creating a new window? In your debt, Logan
“Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’) Built with home-grown CodeProject components! -”-”-
-
I have a couple questions for WPF that I hope have simple answers: Suppose I want to make my interface modular and abstract, so that I don't need to group everything into a single xaml file. What is the simplest and most efficient way to dynamically swap out pieces of a xaml interface? In WinForms this could be done simply by using panels, and changing the child control(s) of the panel. Is there a similar idea in WPF? And relatedly, what's the best way to define xaml fragments that aren't entire windows themselves. User controls? Pages? And finally (bonus, unrelated question): is WPF layout strictly grid/hierarchically-based? If I want a fragment such as the above to appear floating over the other elements in a window/grid, can i do that without creating a new window? In your debt, Logan
“Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’) Built with home-grown CodeProject components! -”-”-
logan1337 wrote:
Suppose I want to make my interface modular and abstract, so that I don't need to group everything into a single xaml file. What is the simplest and most efficient way to dynamically swap out pieces of a xaml interface?
The architecture you want to consider is the Composite Application Guidance[^]. This architecture is designed to apply the "hot swapping" because it uses IoC. Please have a look at this[^] link for more details.
logan1337 wrote:
And relatedly, what's the best way to define xaml fragments that aren't entire windows themselves. User controls? Pages?
Well - I'm partial to User controls myself.
logan1337 wrote:
If I want a fragment such as the above to appear floating over the other elements in a window/grid, can i do that without creating a new window?
Oh yes - WPF is full of funky 3D goodness that allows you to move elements through 3D space.
Deja View - the feeling that you've seen this post before.
-
logan1337 wrote:
Suppose I want to make my interface modular and abstract, so that I don't need to group everything into a single xaml file. What is the simplest and most efficient way to dynamically swap out pieces of a xaml interface?
The architecture you want to consider is the Composite Application Guidance[^]. This architecture is designed to apply the "hot swapping" because it uses IoC. Please have a look at this[^] link for more details.
logan1337 wrote:
And relatedly, what's the best way to define xaml fragments that aren't entire windows themselves. User controls? Pages?
Well - I'm partial to User controls myself.
logan1337 wrote:
If I want a fragment such as the above to appear floating over the other elements in a window/grid, can i do that without creating a new window?
Oh yes - WPF is full of funky 3D goodness that allows you to move elements through 3D space.
Deja View - the feeling that you've seen this post before.
Thanks I will take a(nother) look at that. I had skimmed it earlier, but I thought that since it required an actual DLL that it was something way more than what I was looking for.
“Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’) Built with home-grown CodeProject components! -”-”-
-
Thanks I will take a(nother) look at that. I had skimmed it earlier, but I thought that since it required an actual DLL that it was something way more than what I was looking for.
“Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’) Built with home-grown CodeProject components! -”-”-
logan1337 wrote:
but I thought that since it required an actual DLL that it was something way more than what I was looking for.
I hate to say this, but it drops in quite a few. You get the Unity Dll as well.
Deja View - the feeling that you've seen this post before.
-
logan1337 wrote:
but I thought that since it required an actual DLL that it was something way more than what I was looking for.
I hate to say this, but it drops in quite a few. You get the Unity Dll as well.
Deja View - the feeling that you've seen this post before.
:P I'm just surprised that WPF wasn't designed to be modular from the start. It seems too web-page-like, when even web pages are now becoming dynamic and modular.
“Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’) Built with home-grown CodeProject components! -”-”-
-
:P I'm just surprised that WPF wasn't designed to be modular from the start. It seems too web-page-like, when even web pages are now becoming dynamic and modular.
“Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’) Built with home-grown CodeProject components! -”-”-
logan1337 wrote:
I'm just surprised that WPF wasn't designed to be modular from the start. It seems too web-page-like, when even web pages are now becoming dynamic and modular
Well, the big issue with WPF is that it's totally different to Win Forms programming, so the standards and techniques are being defined by the gods of WPF (like the Rockstar, Dr WPF, Sacha and the Molenator).
Deja View - the feeling that you've seen this post before.
-
logan1337 wrote:
I'm just surprised that WPF wasn't designed to be modular from the start. It seems too web-page-like, when even web pages are now becoming dynamic and modular
Well, the big issue with WPF is that it's totally different to Win Forms programming, so the standards and techniques are being defined by the gods of WPF (like the Rockstar, Dr WPF, Sacha and the Molenator).
Deja View - the feeling that you've seen this post before.
Different is fine if it's an improvement, but I am really feeling lost that what I want to do is not immediately doable. I can understand when the designers (or "gods") tell you you can't do something the old way because the new way is clearly better (like, say, MVC) but I don't see that as being the case here, at least at my current level of understanding. I mentioned in my rant in the lounge how un-obvious it is to build and share contextual menus between multiple sources, or really to handle any kind of dynamic generation--allow me to ask you this: Suppose I have an objective encapsulation of a "command" that can be applied to an object, and I want those commands to appear in a contextual menu when the target object is right-clicked. The name, icon, tool tip, etc. should all be figured-out from the command itself, and not statically "baked into" the interface. Furthermore, the actual selection of commands should be dynamic, based on some method that runs. I want each MenuItem to be dynamically generated based on these "rules", and constructed based on properties of the command (i.e. the name, icon, etc.), and then to populate that context menu with the generated items... but more complicated things I would like to use (as I mentioned in the original question) an abstract modular approach, where I can define the rendering of a particular object dynamically based on an abstract XAML object, such as a user control. Is this still possible in WPF? Obviously it isn't in XAML, but tell me I can still perform this kind of dynamic generation in code. Maybe I have the wrong impression of WPF because I'm trying to do everything in XAML when I should be looking at the programmatic methods. Your thoughts?
“Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’) Built with home-grown CodeProject components! -”-”-
-
Different is fine if it's an improvement, but I am really feeling lost that what I want to do is not immediately doable. I can understand when the designers (or "gods") tell you you can't do something the old way because the new way is clearly better (like, say, MVC) but I don't see that as being the case here, at least at my current level of understanding. I mentioned in my rant in the lounge how un-obvious it is to build and share contextual menus between multiple sources, or really to handle any kind of dynamic generation--allow me to ask you this: Suppose I have an objective encapsulation of a "command" that can be applied to an object, and I want those commands to appear in a contextual menu when the target object is right-clicked. The name, icon, tool tip, etc. should all be figured-out from the command itself, and not statically "baked into" the interface. Furthermore, the actual selection of commands should be dynamic, based on some method that runs. I want each MenuItem to be dynamically generated based on these "rules", and constructed based on properties of the command (i.e. the name, icon, etc.), and then to populate that context menu with the generated items... but more complicated things I would like to use (as I mentioned in the original question) an abstract modular approach, where I can define the rendering of a particular object dynamically based on an abstract XAML object, such as a user control. Is this still possible in WPF? Obviously it isn't in XAML, but tell me I can still perform this kind of dynamic generation in code. Maybe I have the wrong impression of WPF because I'm trying to do everything in XAML when I should be looking at the programmatic methods. Your thoughts?
“Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’) Built with home-grown CodeProject components! -”-”-
You can reuse items just by giving them a key. A really fun thing to do is to define your item in a different assembly which can be loaded at runtime, just by using
ContextMenu={DynamicResource MyMenu}
in your item.Deja View - the feeling that you've seen this post before.
-
You can reuse items just by giving them a key. A really fun thing to do is to define your item in a different assembly which can be loaded at runtime, just by using
ContextMenu={DynamicResource MyMenu}
in your item.Deja View - the feeling that you've seen this post before.
That's good to know. Guess I was just looking in the wrong places.
“Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’) Built with home-grown CodeProject components! -”-”-