user2582770
user2582770

Reputation: 411

WPF Static Status Bar Message Access

I am creating a WPF application and in the MainWindow.xaml code I have a status bar. I have a StatusBarMessage property which is bound to the status bar. I want this property to be static so that I can update the message in any of the view models. Does anyone have suggestion about the best solution for this?

Upvotes: 0

Views: 154

Answers (1)

mm8
mm8

Reputation: 169270

Here is an example of how to bind to and raise change notifications for a static property:

public class StatusBarViewModel
{
    private static string _status;
    public static string Status
    {
        get => _status;
        set
        {
            _status = value;
            StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(Status)));
        }
    }

    public static event PropertyChangedEventHandler StaticPropertyChanged;
}

XAML:

 <TextBlock Text="{Binding Path=(local:StatusBarViewModel.Status)}"/>

Upvotes: 1

Related Questions