I have developed some MVVM based WPF code and am in need of some minor refactoring but prior to doing that I need to decide the best architecture.
I originally started with an application that could present several similar (but separate) representations of my data. Let's call it RecordsViewModel
which had a corresponding RecordsView
. As time went on, I introduced a SettingsViewModel
which was passed into the constructor of the RecordsViewModel
and published visibly (allowing RecordsView
to use it). The SettingsViewModel
is registered to so that changes are reflected in all of my views.
Now I want to split RecordsView
a little because it now contains two distinct views.
The problem I have is:
- the new (
RecordsMainView
andRecordsAlternativeView
) both want to see Settings. - unlike the earlier
RecordsView
which is programmatically instantiated, these new views are instantiated from Xaml (default constructor).
So my options seem to be:
- Walk the Tree Model upwards to find a parent with a Settings
- Make Settings a
DependencyProperty
on the controls and make the Xaml join the Property to the instance. - Make
SettingsViewModel
a Singleton.
Any other, better, options? Which would you consider best?