1

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 ?

AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
Yaron Levi
  • 12,535
  • 16
  • 69
  • 118

1 Answers1

0

It's a known bug and it seems it's still happening in Silverlight 4. Always use TwoWay binding with SelectedItem.

Binding ComboBox.SelectedItem in Silverlight

Community
  • 1
  • 1
alf
  • 18,372
  • 10
  • 61
  • 92