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

ItemsSource cannot be changed on a Picker on Windows #9239

Closed
pekspro opened this issue Aug 6, 2022 · 0 comments · Fixed by #9584
Closed

ItemsSource cannot be changed on a Picker on Windows #9239

pekspro opened this issue Aug 6, 2022 · 0 comments · Fixed by #9584

Comments

@pekspro
Copy link

pekspro commented Aug 6, 2022

Description

On a Picker, it's not possible to change the ItemsSource after it has been set on Windows (works find on Android). At least not easily. Every time you try to change, the previous set list is used instead.

Steps to Reproduce

  1. Create a new MAUI application.
  2. Replace MainPage.xaml:
    <VerticalStackLayout 
        Spacing="25" 
        Padding="30,0" 
        VerticalOptions="Start">

        <HorizontalStackLayout Spacing="25">
            <VerticalStackLayout>
                <Label Text="Available colors:" />
                <Label Text="{Binding Colors[0]}" />
                <Label Text="{Binding Colors[1]}" />
                <Label Text="{Binding Colors[2]}" />
            </VerticalStackLayout>

            <VerticalStackLayout>
                <Label Text="Select a color:" />
                <Picker ItemsSource="{Binding Colors}" SelectedIndex="{Binding SelectedColorIndex}" />
            </VerticalStackLayout>
        </HorizontalStackLayout>

        <Button 
            x:Name="CounterBtn"
            Text="Show blue colors"
            Clicked="OnCounterClicked"
            HorizontalOptions="Start"
            />
        
    </VerticalStackLayout>
  1. Replace MainPage.xaml.cs:
public MainPage()
{
    InitializeComponent();

    BindingContext = this;
}

public List<string> Colors { get; set; } = new List<string>()
{
    "Red",
    "LightRed",
    "DarkRed",
};

public int SelectedColorIndex { get; set; }

private int ChangeCount = 0;

private void OnCounterClicked(object sender, EventArgs e)
{
    ChangeCount++;
    Colors = new List<string>()
    {
        "Blue " + ChangeCount,
        "LightBlue " + ChangeCount,
        "DarkBlue " + ChangeCount,
    };

    OnPropertyChanged(nameof(Colors));
    SelectedColorIndex = 0;
    OnPropertyChanged(nameof(SelectedColorIndex));
}
  1. Run the application. The default red colors are visible:

image

  1. Press the button to change to blue colors. They are not changed in the picker:

image

  1. Press the button again. Now they are changed in the picker, but the previous list is used:

image

Full repro: https://github.com/pekspro/MauiIssues/tree/9239_ItemsSource_cannot_be_changed_on_a_Picker

Version with bug

6.0.408 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows 10.0.17763.0

Did you find any workaround?

Using an ObservableCollection<string> works if it is set once and the individual items are changed.

Relevant log output

No response

@pekspro pekspro added the t/bug Something isn't working label Aug 6, 2022
@Redth Redth added legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor area-controls-picker Picker labels Aug 8, 2022
@Redth Redth added this to the .NET 7 Planning milestone Aug 8, 2022
@jsuarezruiz jsuarezruiz self-assigned this Aug 23, 2022
rmarinho pushed a commit that referenced this issue Aug 23, 2022
 #9496

* Notify changes in Picker ItemsSource (without using ObservableCollection)

* Added device test
@ghost ghost locked as resolved and limited conversation to collaborators Sep 22, 2022
@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants