RibbonComboBox not showing initial selected value
I have a strange behavour when using WPF RibbonComboBox. When starting the application, the RibbonComboBox does not show the initial selected value.
This is my XAML
This is the window code behind and viewmodel
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
namespace WpfApp1
{
public partial class MainWindow : Window, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public MainWindow()
{
InitializeComponent();
MyItems =
[
new MyItem() { Text = "Val 0", Value = 0 },
new MyItem() { Text = "Val 1", Value = 1 },
new MyItem() { Text = "Val 2", Value = 2 },
];
// Pre-Select Value 1
MySelectedValue = 1;
DataContext = this;
}
public ObservableCollection MyItems { get; private set; }
public int _mySelectedValue;
public int MySelectedValue
{
get => _mySelectedValue;
set
{
_mySelectedValue = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MySelectedValue)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MySelectedText)));
}
}
public string MySelectedText
{
get => $"Value is {MySelectedValue}";
}
}
public class MyItem
{
public string Text { get; set; }
public int Value { get; set; }
}
}
Problem:
MySelectedValue is pre-set to 1, but the ComboBox stays empty.
Anyone a clue what i'm missing?