The ComboBox doesn't select value if it's enum
See original GitHub issueDescribe 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
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:
- Created 2 years ago
- Reactions:3
- Comments:12 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.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.