WPF - name of the data binding window for viewing model properties

I am trying to bind a window title to a property in my view model, for example:

Title="{Binding WindowTitle}"

The property looks like this:

    /// <summary>
    /// The window title (based on profile name)
    /// </summary>
    public string WindowTitle
    {
        get { return CurrentProfileName + " - Backup"; }
    }

The CurrentProfileName property is derived from another property (CurrentProfilePath), which is set when someone opens or saves a profile. At initial startup, the window title is set correctly, but when the CurrentProfilePath property changes, the change does not turn into the window title, as I expected.

I don’t think I can use the dependency property here because the property is derived. The underlying property from which it is derived is a dependency property, but this does not seem to have any effect.

How can I make the form header self-update based on this property?

+5
1

, WPF , WindowTitle CurrentProfileName. INotifyPropertyChanged, CurrentProfileName, PropertyChanged CurrentProfileName WindowTitle

private string _currentProfileName;
public string CurrentProfileName
{
    get { return __currentProfileName; }
    set
    {
        _currentProfileName = value;
        OnPropertyChanged("CurrentProfileName");
        OnPropertyChanged("WindowTitle");
    }
}

INotifyPropertyChanged:

public class MyClass : INotifyPropertyChanged
{
    // The event declared in the interface
    public event PropertyChangedEventHandler PropertyChanged;

    // Helper method to raise the event
    protected virtual void OnPropertyChanged(string propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
            handler(this, new PropertyChangedEventArgs(propertyName);
    }

    ...
}
+9

All Articles