I came across the following problem. I have a checkbox, the IsChecked property IsChecked bound to the CLR property in my MainWindow class. Here is the source code.
Code behind ( MainWindow.xaml.cs ):
namespace MenuItemBindingTest { public partial class MainWindow : Window, INotifyPropertyChanged { private bool m_backedVariable = false; public bool IsPressAndHoldEnabled { get { return this.m_backedVariable; } set { this.m_backedVariable = value; OnPropertyChanged("IsPressAndHoldEnabled"); MessageBox.Show("Item changed: " + this.m_backedVariable); } } public MainWindow() { InitializeComponent(); this.m_checkbox.DataContext = this; } public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string propertyName) { if (this.PropertyChanged != null) { this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } } }
XAML Code ( MainWindow.xaml ):
<Window x:Class="MenuItemBindingTest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Binding Problem Test" Width="525" Height="350"> <DockPanel> <CheckBox x:Name="m_checkbox" IsChecked="{Binding IsPressAndHoldEnabled}" HorizontalAlignment="Center" VerticalAlignment="Center" Content="Is Press and Hold enabled"/> </DockPanel> </Window>
Now the problem is that the installation attribute for the IsPressAndHoldEnabled property IsPressAndHoldEnabled never called (i.e. the message box is never displayed) when the user checks or unchecks the box. However, it works when I rename a property to something else - for example, IsPressAndHoldEnabled2 .
Now my question is: why can't I use IsPressAndHoldEnabled as the name for my property? Does this have anything to do with the Stylus.IsPressAndHoldEnabled existing property?
source share