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

More problems with the Picker #22121

Open
antonycartwright opened this issue Apr 29, 2024 · 0 comments
Open

More problems with the Picker #22121

antonycartwright opened this issue Apr 29, 2024 · 0 comments
Labels
area-controls-picker Picker s/triaged Issue has been reviewed t/bug Something isn't working

Comments

@antonycartwright
Copy link

antonycartwright commented Apr 29, 2024

Description

Hi everyone,

There are more problems with the Picker control. Really basic problems. About a week ago, I explained that in a form, you can't initialise the value of the Picker on load. I explained a workaround also. In a simple form displaying one record, you can set the SelectedIndex from the codebehind, then subsequently, this calls whatever events are required for it to display the text.

However, when you're displaying many records, this gets very difficult. How can you do this from the codebehind when it's bound automatically? With massive difficulty.

Let's say we have a datatamplate, and within it we have this picker:

**<Picker Grid.Column="2" BindingContext="{x:Reference MyPage}" ItemsSource="{Binding Decks}" ItemDisplayBinding="{Binding Name}" SelectedItem="{Binding Deck, Mode=OneTime}" SelectedIndexChanged="Picker_SelectedIndexChanged_1" />**

It binds fine, but with this bug, the initial value, or the valuje from the binding won't show. With my workaround, I could set the SelectedIndex, but how when you're showing many records? It needs to be able to do it itself while binding.

image

The documentation says this:

image

Here's another (ridiculous) workaround:

<Label x:Name="lblDeck" Grid.Column="2" Text="{Binding Deck.Name}" VerticalTextAlignment="Center" Padding="10,10,10,10"/> <Picker Grid.Column="2" BindingContext="{x:Reference MyPage}" ItemsSource="{Binding Decks}" ItemDisplayBinding="{Binding Name}" SelectedItem="{Binding WordList.Deck, Mode=OneTime}" SelectedIndexChanged="Picker_SelectedIndexChanged_1" />

Basically, use a label as well as a Picker. Draw the label over the Picker and bind the label. The label will then show the correct value. Since the Picker doesn't initialise by default, it will be blank, and the label will show the value. Add a SelectedIndexChanged event to the Picker. When the value is changed, make the label invisible, as now the Picker can display! It's absolutely ridiculous, but ti works.

@antonycartwright antonycartwright added the t/bug Something isn't working label Apr 29, 2024
@dotnet-policy-service dotnet-policy-service bot added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Apr 29, 2024
@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
@ninachen03 ninachen03 added the s/triaged Issue has been reviewed label May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-picker Picker s/triaged Issue has been reviewed t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants