Problem with SelectedItem of WPF Editable ComboBox with DataTemplate

匆匆过客 提交于 2019-12-04 12:45:38

I've submitted the same question to MSDN WPF Forum and it seems like a Microsoft bug. There's a workaround I found, ugly, but it's working. Here's the modified code behind:

    public Window1()
    {
        InitializeComponent();
        DataContext = new Data();
        DataContextChanged += delegate { contentControl.UpdateLayout(); };
    }

    void ChangeData_Click(object sender, RoutedEventArgs e)
    {
        DataContext = null;
        DataContext = new Data();
    }

Note that both setting the DataContext to null and calling UpdateLayout() on DataContextChanged are needed to solve this issue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!