I've following code in my wpf App.xaml.cs file:
MainWindowViewModel.cs
MainWindow.xaml
But this does not seem to work.Although the method in app.xaml.cs is getting invoked, I dont see the error getting displayed message on the UI.What could be wrong here please?
(I'm able to see the message when I set the DisplayMessage and DisplayMessageForegroundColor properties from within MainWindowViewModel though).
Please advise.
Thanks.
void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { var mainVM = MainWindowViewModel.Instance; mainVM.DisplayMessage = string.Format("Something went wrong and it has been logged...If the problem persists, please contact {0}.", mainVM.NotificationsReceiver); mainVM.DisplayMessageForegroundColor = "Red"; e.Handled = true; }
MainWindowViewModel.cs
public string DisplayMessage { get { return m_displayMessage; } set { m_displayMessage = value; OnPropertyChanged("DisplayMessage"); } } public string DisplayMessageForegroundColor { get { return m_displayMessageForegroundColor; } set { m_displayMessageForegroundColor = value; OnPropertyChanged("DisplayMessageForegroundColor"); } }
MainWindow.xaml
<Label Content="{Binding DisplayMessage}" Foreground="{Binding DisplayMessageForegroundColor}" Grid.Column="1" HorizontalAlignment="Left" Height="33" Margin="14,660,0,0" Grid.Row="1" VerticalAlignment="Top" Width="693" Grid.ColumnSpan="3"/>
But this does not seem to work.Although the method in app.xaml.cs is getting invoked, I dont see the error getting displayed message on the UI.What could be wrong here please?
(I'm able to see the message when I set the DisplayMessage and DisplayMessageForegroundColor properties from within MainWindowViewModel though).
Please advise.
Thanks.