The Test property should inform other components when its value changes, for example. implementing the INotifyPropertyChanged interface in the containing class as follows:
class Window1 : Window, INotifyPropertyChanged { ... private string m_Test; public string Test { get { return m_Test; } set { m_Test = value; OnPropertyChanged("Test"); } } }
You can then change the Test value from anywhere to using the property ( Test = "newValue"; ), and the changes will be displayed in the user interface.
If you really need to change the value of the property when ContextMenu displayed, use the Opend ContextMenu event:
Xaml:
<ContextMenu Opened="UpdateTest"> <MenuItem Header="{Binding Test}" /> </ContextMenu>
Code for:
private void UpdateTest(object sender, RoutedEventArgs e) {
source share