Can a property depend on a property in an instance of another class?
See original GitHub issueI’m considering having shared/global state (e.g. AllTodos
) in a service (implementing INotifyPropertyChanged
) which is injected into all viewmodels that need access to shared state. These viewmodels would then have their own properties which are more or less just projections of the shared state, e.g. the TodoListViewModel
could have a property called FilteredTodos
which depend on the injected service’s AllTodos
property (as well as its own SearchTerm
property or similar).
For example:
public class SharedState : INotifyPropertyChanged
{
public IList<Project> Projects { get; set; }
public bool IsRefreshing { get; set; }
// etc.
}
public class TodoListViewModel : INotifyPropertyChanged
{
// Could also be a property if necessary
private SharedState sharedState;
public TodoListViewModel(SharedState sharedState)
=> this.sharedState = sharedState;
public bool IsRefreshingIndicatorVisible => this.sharedState.IsRefreshing;
public bool IsProjectListVisible => !this.sharedState.IsRefreshing;
public bool SearchTerm { get; set; }
public bool FilteredTodos => this.sharedState.AllTodos
.Where(todo => todo.MatchesSearchTerm(this.SearchTerm));
}
Is it possible, using PropertyChanged.Fody, to set up dependencies correctly in this case? For example, TodoListViewModel.IsRefreshingIndicatorVisible
would notify whenever SharedState.IsRefreshing
changes, and TodoListViewModel.FilteredTodos
would notify whenever SharedState.AllTodos
or TodoListViewModel.SearchTerm
changes.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
@navozenko sorry i think reference tracking of nested instances is outside the scope of this project
@shtse8 happy to see a PR that show how this would work