ComboBox SelectedItem throws exception in Windows 10

0

following code works fine under Windows 8.1 and I recently upgraded my OS to Windows 10 and it throws an exception.

Here is a screenshot of the exception enter image description here

This is the XAML code:

  <ComboBox Grid.Row="3" HorizontalContentAlignment="Left" HorizontalAlignment="Left"
                      TabIndex="2" VerticalAlignment="Center"
                      ItemsSource="{Binding DateFormats}"
                      SelectedItem="{Binding DateFormatSelected, Mode=TwoWay}">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Value}" />
                        </StackPanel>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>

When I removed the part "SelectedItem" it works but I need the SelectedItem to be displayed. Please help.

Here the event viewer application error details. It doesn't provide much info either

Faulting application name: BoardPACWinApp.exe, version: 0.0.0.1, time stamp: 0x55bdb705 Faulting module name: Windows.UI.Xaml.dll, version: 10.0.10240.16397, time stamp: 0x55af0da4 Exception code: 0xc000027b Fault offset: 0x00722f90 Faulting process id: 0x1e48 Faulting application start time: 0x01d0cd2970f53bb1 Faulting application path: D:\Projects\BoardPACWinApp\BoardPACWinApp\bin\x86\Debug\AppX\BoardPACWinApp.exe Faulting module path: C:\Windows\System32\Windows.UI.Xaml.dll Report Id: 38e21b5c-cf75-4849-81df-01bb412c291a Faulting package full name: IronOneTechnologiesPvtLtd.BoardPACWinDemo_3.14.35.2_x86__na7z394ep8t7e Faulting package-relative application ID: App

xaml
windows-runtime
windows-store-apps
winrt-xaml
windows-10
asked on Stack Overflow Aug 2, 2015 by SurenSaluka • edited Aug 24, 2015 by Amy Peng - MSFT

2 Answers

1

I was getting a similar exception and it was caused because I was manipulating the ItemsSource binding property (List<>) when the binding process started. Now I make all the manipulations on a temp collection which I assign to the binded property when all manipulations to the collection are finished.

Hope this helps...

answered on Stack Overflow Jun 30, 2016 by Asier Peña
0

What I've done is do the SelectedItem binding using the code view.

Here's my XAML code:

<ComboBox x:Name="DateFormatsComboBox" Grid.Row="3" Style="{StaticResource CustomBlueComboBoxStyle}"
                  ItemsSource="{Binding DateFormats}" ItemContainerStyle="{StaticResource CustomBlueComboBoxItemStyle}">
            <!--NOTE: Removed coz Windows 10 had issues | 2015-08-16 | SurenM -->
            <!--SelectedItem="{Binding DateFormatSelected, Mode=TwoWay}"-->
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Value}" />
                    </StackPanel>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>

Here's my C# code:

//NOTE: Windows 10 had issues with XAML Combobox SelectItem, so it was brought to code behind
            DateFormatsComboBox.SelectedItem = _model.DateFormatSelected;

NOTE: _model.DateFormatSelected is a CustomKeyValuePair<string, string>

This approach is tested on Windows 8.1 and Windows 10 both and it works great.

answered on Stack Overflow Feb 19, 2016 by SurenSaluka

User contributions licensed under CC BY-SA 3.0