Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ComboBox items don't update properly on ItemsSource binding source collection changes #256

Closed
dymanoid opened this issue Jan 26, 2016 · 11 comments
Assignees
Labels
Milestone

Comments

@dymanoid
Copy link

Let's bind a Fluent ComboBox ItemsSource propery to an ObservableCollection containing at least one item:

this.Items = new ObservableCollection<string> { "first" };

XAML:

<f:ComboBox IsEditable="False" ItemsSource="{Binding Items}"/>

How to reproduce the issue:

  1. Start the test app.
  2. Open the ComboBox drop down and close it (e.g. by selecting any item or just clicking somewhere outside the control). The source collection items are displayed properly.
  3. Add a new item into the source ObservableCollection.
  4. Open the ComboBox drop down again: the item doesn't appear in the drop down.
  5. Close the drop down and again add an item into the source collection.
  6. Open the drop down: now the item from the step 3 is visible, but there's no item from step 5.

If we don't open the drop down first (skip steps 2 and 4), then all items will appear correctly in the drop down. Yeah, you need to open it to check the items, so after that all new items will not be added immediately.

Sometimes the new item appears in the drop down though, even if the drop down has been opened and closed first. But that is a rare case anyway.

@batzen
Copy link
Member

batzen commented Jan 28, 2016

Are you really sure that this issue does not occur with a regular ComboBox?
We directly inherit from the regular WPF ComboBox and have no special code handling items changes.

@dymanoid
Copy link
Author

Yes, I've checked the default WPF ComboBox and it seems to work properly. I can build a small repro app if you'd like to have one. But it is really very simple, two lines of code.

@dymanoid
Copy link
Author

So here is the code to reproduce the issue.

XAML markup:

<f:RibbonWindow x:Class="FluentRibbonComboBox.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:l="clr-namespace:FluentRibbonComboBox"
        xmlns:f="urn:fluent-ribbon"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <f:RibbonWindow.DataContext>
        <l:ViewModel/>
    </f:RibbonWindow.DataContext>
    <Grid>
        <f:Ribbon>
            <f:RibbonTabItem Header="Test">
                <f:RibbonGroupBox Header="Test">
                    <ComboBox IsEditable="False" ItemsSource="{Binding Items}"/>
                    <f:ComboBox IsEditable="False" ItemsSource="{Binding Items}"/>
                    <f:Button Header="Add items" Click="Button_Click"/>
                </f:RibbonGroupBox>
            </f:RibbonTabItem>
        </f:Ribbon>
    </Grid>
</f:RibbonWindow>

The code-behind:

public partial class MainWindow : RibbonWindow
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        ViewModel vm = this.DataContext as ViewModel;
        vm.Items.Add("Added item " + vm.Items.Count);
    }
}

And the "view model":

class ViewModel
{
    public ViewModel()
    {
        this.Items = new ObservableCollection<string> { "Item 0", "Item 1" };
    }

    public ObservableCollection<string> Items { get; private set; }
}

As you see, there is nothing special, just as simple as possible. Though the WPF ComboBox displays its items properly while the Fluent Ribbon ComboBox does not (in that use case as described: first open the drop-down, then add items).

@batzen
Copy link
Member

batzen commented Jan 28, 2016

Will have a look at it later.

@batzen
Copy link
Member

batzen commented Jan 28, 2016

Had no time today, I am pretty busy writing the showcase application for ControlzEx and fixing all WindowChrome issues there.
Will have a look at your issue tomorrow.

@batzen batzen added this to the 4.0.0 milestone Jan 29, 2016
@batzen batzen self-assigned this Jan 29, 2016
@batzen batzen closed this as completed in b61a894 Jan 29, 2016
floele-ww pushed a commit to WinWorker/Fluent.Ribbon that referenced this issue Jan 30, 2016
floele-ww pushed a commit to WinWorker/Fluent.Ribbon that referenced this issue Jan 30, 2016
batzen added a commit that referenced this issue Feb 5, 2016
batzen added a commit that referenced this issue Feb 5, 2016
@dymanoid
Copy link
Author

It seems that the issue appears again in v4.0.3.394. Additional side effect: when removing an item from bound collection, an empty row is still being shown for this item in the drop-down. Should I create a new issue or better reopen this one?

@batzen
Copy link
Member

batzen commented Jun 16, 2016

Could you try to reproduce this with the current version from the develop branch?
You can get the latest unrelease nuget package from the appveyor nuget feed at https://ci.appveyor.com/nuget/fluent-ribbon

@dymanoid
Copy link
Author

Yes, I could reproduce it with the version 4.0.3.398 obtained via appveyor.

@batzen
Copy link
Member

batzen commented Jun 16, 2016

That's not the latest (prerelease) version from the develop branch.
The latest version from there is 5.0.0-dev0419.

@dymanoid
Copy link
Author

Sorry, my fault. Didn't set the "Include prerelease" flag. The dev0419 revision seems to be OK! Any plans when v5.0 comes out?

@batzen
Copy link
Member

batzen commented Jun 16, 2016

Currently not. Got very limited time to work on OSS at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants