title: MVVM - Update StatusBar from various views
body: <p>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.</p>
  
  <p>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!!</p>
  
  <p><img src="https://i.stack.imgur.com/HcZAY.jpg" alt="enter image description here"></p>
  
  <p>ViewModelBase.vb</p>
  
  <pre><code>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
  </code></pre>
  
  <p>StatusViewModel.vb</p>
  
  <pre><code>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 &lt;&gt; _statusBarText Then
                  _statusBarText = value
                  OnPropertyChanged("StatusBarText")
              End If
          End Set
      End Property
  End Class
  </code></pre>
  
  <p>MainViewModel.vb</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Status.xaml (UserControl)</p>
  
  <pre><code>&lt;StatusBar DataContext="{Binding StatusViewModel}"&gt;
  ...
  &lt;w:StdTextBlock Text="{Binding StatusText, UpdateSourceTrigger=PropertyChanged}" /&gt;
  </code></pre>
  
  <p>Application.xaml.vb</p>
  
  <pre><code>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
  </code></pre>
  
  <p>MainWindow.xaml</p>
  
  <pre><code>&lt;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"&gt;
      &lt;Grid&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="*"/&gt;
              &lt;RowDefinition Height="20"/&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;local:Status Grid.Row="1" /&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>