Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Issue with app.xaml.cs to MainViewmodel communication

$
0
0
I've following code in my wpf App.xaml.cs file:

     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.







Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>