In a simple MVVM application, I can add a binding to some property in the view. The property may access another object and return a property value from it. Say I want to display the active project in the view. If no project is active, a special note shall be displayed.
Now when the project is renamed, the name should be updated in the view. If I just returned the project's name in the property, it won't be updated of course.
So I thought I could just bind the view to another binding created in the property, that should forward the PropertyChanged event and update the view accordingly. But I see "System.Windows.Data.Binding" instead of the intended result of the binding like "Project: XYZ".
The project can be renamed anywhere so I'd like to avoid raising the PropertyChanged event for this ViewModel on my own from there. Things should be a little smarter on their own and not need to be pushed from everywhere (which you often forget at least once when things get more complex).
Here's the code:
XAML View:
<TextBlock Text="{Binding ActiveProjectName}"/> C# ViewModel:
public object ActiveProjectName { get { if (ActiveProject != null) { // This works but won't update automatically: //return "Project: " + ActiveProject.Name; // This does not work at all: return new Binding("Name") { Source = ActiveProject, StringFormat = "Project: {0}" }; } return "(No active project)"; } } Is that possible at all and how does it work right?