I am putting my first MVVM project together. I have a StatusBar that will be updated from various views (UserControls) from within the application. Each view will have its own DataContext. My original thought was to create a ViewModelBase class which implemented the INotifyPropertyChanged interface and also contained a public property to bind the the text of my StatusBar to. All other ViewModels within the application would then inherit the ViewModelBase class. Of course, this does not work. How can I accomplish this? I am not using MVVM Light or any other frameworks and I am programming in vb.net. Thanks in advance.
Update - Below is the translation of what Garry proposed in the 2nd answer, I am still unable to modify the status text from the MainViewModel?? Anyone see a problem with the vb translation of his c# code? This MVVM transition is causing major hair loss!!

ViewModelBase.vb
Imports System.ComponentModel
Public Class ViewModelBase
Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler _
Implements INotifyPropertyChanged.PropertyChanged
Protected Sub OnPropertyChanged(ByVal propertyName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
End Class
StatusViewModel.vb
Public Interface IStatusBarViewModel
Property StatusBarText() As String
End Interface
Public Class StatusBarViewModel
Inherits ViewModelBase
Implements IStatusBarViewModel
Private _statusBarText As String
Public Property StatusBarText As String Implements IStatusBarViewModel.StatusBarText
Get
Return _statusBarText
End Get
Set(value As String)
If value <> _statusBarText Then
_statusBarText = value
OnPropertyChanged("StatusBarText")
End If
End Set
End Property
End Class
MainViewModel.vb
Public Class MainViewModel
Inherits ViewModelBase
Private ReadOnly _statusBarViewModel As IStatusBarViewModel
Public Sub New(statusBarViewModel As IStatusBarViewModel)
_statusBarViewModel = statusBarViewModel
_statusBarViewModel.StatusBarText = "Test"
End Sub
End Class
Status.xaml (UserControl)
<StatusBar DataContext="{Binding StatusViewModel}">
...
<w:StdTextBlock Text="{Binding StatusText, UpdateSourceTrigger=PropertyChanged}" />
Application.xaml.vb
Class Application
Protected Overrides Sub OnStartup(e As System.Windows.StartupEventArgs)
Dim iStatusBarViewModel As IStatusBarViewModel = New StatusBarViewModel()
Dim mainViewModel As New MainViewModel(iStatusBarViewModel)
Dim mainWindow As New MainWindow() With { _
.DataContext = mainViewModel _
}
mainWindow.Show()
End Sub
End Class
MainWindow.xaml
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:GlobalStatusBarTest"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="20"/>
</Grid.RowDefinitions>
<local:Status Grid.Row="1" />
</Grid>
</Window>