This is the purest example i can give.
I have a simple ComboBox :
<ComboBox ItemsSource="{Binding ItemsSource}" SelectedItem="{Binding SelectedItem, Mode=OneWay}"/>
This is the CodeBehind:
public partial class MainPage : UserControl, INotifyPropertyChanged
{
private List<string> m_ItemsSource;
public List<string> ItemsSource
{
get
{
return m_ItemsSource;
}
set
{
m_ItemsSource = value;
PropertyChanged(this, new PropertyChangedEventArgs("ItemsSource"));
}
}
private string m_SelectedItem;
public string SelectedItem
{
get
{
return m_SelectedItem;
}
set
{
m_SelectedItem = value;
PropertyChanged(this, new PropertyChangedEventArgs("SelectedItem"));
}
}
public MainPage()
{
InitializeComponent();
DataContext = this;
ItemsSource = new List<string>()
{
"Value A",
"Value B"
};
}
private void button1_Click(object sender, RoutedEventArgs e)
{
SelectedItem = "Value A";
}
private void button2_Click(object sender, RoutedEventArgs e)
{
SelectedItem = "Value B";
}
public event PropertyChangedEventHandler PropertyChanged;
}
For some reason, the SelectedItem in the ComboBox updates correctly on the first button click but then stops to respond.
But strangely enough, when changing to Mode=TwoWay, it works.
I specifically need a OneWay binding and don't want the ComboBox to change the property.
Is it a known bug or some weird design decision ?