picoe / Eto

Cross platform GUI framework for desktop and mobile applications in .NET
Other
3.68k stars 334 forks source link

[GTK2] controls with SelectedIndex get set to -1 #539

Open se5a opened 8 years ago

se5a commented 8 years ago

Where a control that has a SelectedIndex and the SelectedIndex is bound to a viewmodel, under GTK2 the SelectedIndex gets set to -1. WPF does not exhibit this behavior.

Tested with these controls: ComboBox Dropdown ListBox

Under these environments in windows: eto 2.2 + WPF (normal behavior, Selected index is not reset) eto 2.2 + GTK2 (unexpected behavior, Selected index is reset) eto 2.3 + WPF (normal behavior, Selected index is not reset) eto 2.3 + GTK2 (unexpected behavior, Selected index is reset)

Similar behavior seems to be exhibited in linux mint with GTK 2.2 (not tested with the specific given test example)

Test example: This test throws an exception when the viewmodel's SelectedIndex gets set to -1 https://github.com/se5a/EtoTests/tree/master

Test Instructions: Run the test with WPF as the startup project. Click the "Click Me" button. a new tab will be created with the correct items selected in each of the controls.

Run the test with GTK2 as the startup project. Click the "Click Me" button. An exception will be hit when the ListVM's SelectedIndex gets set to -1;

Modify the ListVM.ThrowSelectedIndexException to false (https://github.com/se5a/EtoTests/blob/master/EtoApp1/Newtab.xeto.cs#L35) Run the test with GTK2 as the startup project. Click the "Click Me" button. a new tab will be created. The ComboBox will have the first item selected. The DropDown will have nothing selected. The Listbox will have nothing selected.

TestInfo: TabPage is created on HandleClickMe method here: https://github.com/se5a/EtoTests/blob/master/EtoApp1/MainForm.xeto.cs#L18

NewTab panel has a NewTabVM as the data context. The individual controls are bound in the xaml to ListVM properties. The NewTab, NewTabVM and ListVM are all in this .cs file for easy viewing for this test: https://github.com/se5a/EtoTests/blob/master/EtoApp1/Newtab.xeto.cs

se5a commented 8 years ago

same test using the latest dev build on this branch: https://github.com/se5a/EtoTests/tree/WithEtoDev

cwensley commented 8 years ago

my guess is that Gtk is firing a SelectedIndexChanged event when the form loads, which shouldn't happen obviously as it should be starting at that.. I'll have to look into it further to figure out why.

cwensley commented 8 years ago

Thanks for submitting the issue btw! It really helps keep track of things (;

se5a commented 8 years ago

No problem. yeah that's the conclusion I was coming to as well. This is the root cause of the NRE I mentioned having problems with in IRC the other day, I can work around that though.