question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The ComboBox doesn't select value if it's enum

See original GitHub issue

Describe the bug Hi, the binding to the ComboBox with SelectedValuePath doesn’t work when I’ve placed the enum to SelectedValue. Please take a look at the following code.

Steps to reproduce the bug

    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
        <ComboBox SelectedValuePath="Value" 
                  DisplayMemberPath="Text"
                  ItemsSource="{x:Bind TestSource}"
                  SelectedValue="{x:Bind MyValue, Mode=TwoWay}"/>
    </StackPanel>
    public sealed partial class MainWindow : Window {
        public MainWindow() {
            TestSource = new DisplayItem[] {
                new DisplayItem(MyValues.Value1, "Value1"),
                new DisplayItem(MyValues.Value2, "Value2"),
            };
            MyValue = TestSource[0].Value;

            this.InitializeComponent();
        }

        public IList<DisplayItem> TestSource { get; }
        public MyValues MyValue { get; set; }
    }

    public enum MyValues { Value1, Value2 }

    public class DisplayItem {
        public DisplayItem(MyValues value, string text) {
            Value = value;
            Text = text;
        }

        public MyValues Value { get; }
        public string Text { get; }
    }

Expected behavior

Screenshots image

image

Version Info

NuGet package version:

[WinUI 3 - Windows App SDK 0.8: 0.8.0] If you’re seeing your issue in older previews of WinUI 3, please try this release.

Windows app type:

UWP Win32
Yes
Windows version Saw the problem?
Insider Build (xxxxx)
May 2021 Update (19043)
October 2020 Update (19042)
May 2020 Update (19041) Yes
November 2019 Update (18363)
May 2019 Update (18362)
October 2018 Update (17763)
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop Yes
Xbox
Surface Hub
IoT

Additional context

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
alexdi220commented, Sep 23, 2021

@GeorgeKerwood Did you try my code? It’s doesn’t work. I know many ways to bind the SelectedItem. And your approach will work. But it has a lot of excessive code. The SelectedValuePath property exists only for one thing - to select a value instead of a whole item. This is a very simple and easy scenario when the ComboBox does “work” instead of you. In this case, you no need to write a code that syncs a real value in the viewmodel\model and the SelectedItem in the ComboBox. It’s a basic feature.

0reactions
github-actions[bot]commented, Jul 29, 2023

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Not able to set "SelectedValue" in Combobox bound with ...
I have tried to resolve it through many different ways. Like I have set enum to Key Value Pair. Tried to use "SelectedIndex"....
Read more >
Combobox with dynamically created items for enum type ...
I have a custom WPF combobox that generates its contents based on an enum type it's ... But now binding to the selected...
Read more >
c# - Loading a combobox with an enum and binding to it
The easiest way to accomplish what you want is to create a list of the possible enum values and data bind that list...
Read more >
Bind DropDownList or ComboBox to Enum - Telerik UI for Blazor
If you want to get the Value to actually be an enum, you will need a model ... when the Value matches the...
Read more >
Re: ENUM LIST type column causing VALID IF error i...
I found if I selected a single item, the row copied fine. A workaround is to move the Valid_If expression into the Suggested_Values...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found