locked
E_UNKNOWN_ERROR when ListBox SelectedIndex==0

    Question

  • If you have a list box bound to some items of a selectedindex value of 0, e.g:
    <ListBox ItemsSource="{Binding Items}" SelectedIndex="0"/>

    At run time you will get another unhelpful Xaml exception:
    "WinRT information: E_UNKNOWN_ERROR [Line: 12 Position: 40]

    Additional information: The text associated with this error code could not be found."

    So there are a couple of issues here. Firstly this should never happen.  This behaviour is inconsistent with WPF and Silverlight which both honour selectedindex as soon as the item is bound.  So that's the first bug.

    The second bug is that it should give a reasonable explanation as to what is going on. It takes quite a long time when you have a large and complicated listbox structure to figure out exactly what the problem is.  This is an unnecessary waste of time, which could be avoided with the correct error message being displayed, but as mentioned above there should be no error message, this is valid xaml.

    Hopefully these two problems can be fixed for the next version of windows.

    Thanks,
    Stefan

    Monday, May 05, 2014 1:08 AM

Answers

  • Hi Stefan,

    Thanks for your feedback. I can reproduce it.

    The problem is as what you told: when the InitializeComponent() method finished, the data binding is not finished yet. As a suggestion, you can do the SelectedIndex=0 after the data binding finished.

    I will submit to our senior engineers as a bug report.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by StefanOlson Monday, May 05, 2014 9:33 AM
    Monday, May 05, 2014 8:25 AM
    Moderator

All replies

  • Hi Stefan,

    Thanks for your feedback. I can reproduce it.

    The problem is as what you told: when the InitializeComponent() method finished, the data binding is not finished yet. As a suggestion, you can do the SelectedIndex=0 after the data binding finished.

    I will submit to our senior engineers as a bug report.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by StefanOlson Monday, May 05, 2014 9:33 AM
    Monday, May 05, 2014 8:25 AM
    Moderator
  • Thanks James, yes, I am now manually assigning the selectedindex in the meantime.
    Monday, May 05, 2014 9:33 AM