Reputation: 411
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
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