Proper MVVM approach for my UI
Posted: 13 Jan 2024, 20:16
Hey! I want to apologize in advance if this topic is too specific, or hard to follow along with.
I've experimented quite a bit now with XAML and styling code, but am just now starting to familiarize myself with MVVM as a whole. I am about to begin tackling some controller-based navigation and I'd like to make sure I am doing things properly from the start! I attached an image, which shows 2 (of a few) possible layouts for my UI. All of these colored boxes, represent list boxes, I have some descriptions below the image:
Where should this be controlled? I am sure there are multiple answers, but what is the most agreed upon approach typically? For mouse-interactions I can have some click events in the code-behind but, if the user presses "A" on an XBox controller (and assume that this should select the green box), then it should also go into the code-behind as a part of the View/code-behind similar to how mouse clicks are bound to control logical focus? Which also decouples the View-specific navigation functionality from the ViewModel data? But is it correct to have controller input in the View layer even?
I guess I am nervous to start designing this system since I have very little experience with MVVM. I'd appreciate some wisdom 🙂 How would you design this system? Where would the code be for each part? ie: Controller logic, focus logic, and selection state for scaling/animating the heights...
Thank you very much!
David,
I've experimented quite a bit now with XAML and styling code, but am just now starting to familiarize myself with MVVM as a whole. I am about to begin tackling some controller-based navigation and I'd like to make sure I am doing things properly from the start! I attached an image, which shows 2 (of a few) possible layouts for my UI. All of these colored boxes, represent list boxes, I have some descriptions below the image:
- Red Box: This list box is a constant height and always occupies the left side of the screen. Focus has no effect on its size.
- Blue Box: This box has its height bound to scale with the amount of elements inside of it. Focus has no effect on its size.
- Green Box: This list box stays compressed until you select it (example 1). When you select it, it expands (example 2).
- Pink Box: This one will fill all available space by default. When it's selected, (since the green box is no longer selected) it will expand.
Where should this be controlled? I am sure there are multiple answers, but what is the most agreed upon approach typically? For mouse-interactions I can have some click events in the code-behind but, if the user presses "A" on an XBox controller (and assume that this should select the green box), then it should also go into the code-behind as a part of the View/code-behind similar to how mouse clicks are bound to control logical focus? Which also decouples the View-specific navigation functionality from the ViewModel data? But is it correct to have controller input in the View layer even?
I guess I am nervous to start designing this system since I have very little experience with MVVM. I'd appreciate some wisdom 🙂 How would you design this system? Where would the code be for each part? ie: Controller logic, focus logic, and selection state for scaling/animating the heights...
Thank you very much!
David,