Open ssaran046 opened 3 years ago
Also #3339
Any updates on this issue?
selectvalue
can work by click button, except first ui loaded.
i'm crazy!
Is anyone able to get SelectedValue
to work with any object type? I can get it to work only if I hot-edit the SelectedValuePath
, which is not ideal.
I am also experiencing this same issue. In my case I am using the Microsoft Toolkit MVVM, and attempting to set the ComboBox.SelectedValue property to a property on the view model, and it's not selecting it from the list, even though the value of the view model property is the same as the value in the list.
Any updates?
I have the same problem as @tuggernuts:
<ComboBox SelectedValue="{x:Bind ViewModel.AlgorithmId, Mode=TwoWay}" ItemsSource="{x:Bind AvailableAlgorithms}"
SelectedValuePath="Id" DisplayMemberPath="Name"
PlaceholderText="nothing selected" />
shows the placeholder text after initialization even though ComboBox.SelectedValue
has a value which is also the value of the Id
-property of one element in ComboBox.ItemsSource
. If I hot-edit ComboBox.SelectedValuePath
from "Id" to something else and back to "Id", the placeholder text disappears and the value of the Name
-property of the correct item appears.
I suppose this is slightly different than the problem described in this issue. But it does not seem worth the effort to create a new issue, when this issues is open for more than 1.5 years.
Same here. After playing with SelectedValue
and SelectedValuePath
I've been unable to get the data updated when the comobox changes.
This is still a bug in WinUI3... is there at least a workaround?
I wish to understand why some important (and sometimes easy) issues are being ignored for long time...
Anyway, I think I found the cause the of the bug after debugging for some minutes.
This bug is caused by two issues in ComboBox:
SelectedValue
and SelectedValuePath
are evaluated before ItemsSource
.ItemsSource
change, ComboBox
does not re-evaluate related properties (SelectedValue
and SelectedValuePath
in this case).[!note] This behavior is observed when using
x:Bind
.Workaround
// In constructor of Page/Window/UserControl/etc...
comboBox.RegisterPropertyChangedCallback(ComboBox.ItemsSourceProperty, OnItemsSourceChanged);
// This will be called whenever ItemsSource has changed
private void OnItemsSourceChanged(DependencyObject sender, DependencyProperty dp)
{
if (comboBox.ItemsSource is not null)
{
comboBox.SelectedValuePath = null;
comboBox.SelectedValuePath = "<the-path-here>";
}
}
Describe the bug
I'm facing the same issue already reported https://github.com/microsoft/microsoft-ui-xaml/issues/3875.
Additionally, The
SelectedValue
property binding is not working for the framework type. So the Combobox item is not selected.Sample: ComboBoxwithEnumvalues.zip
Steps to reproduce the bug
Expected behavior
The Combobox item needs to be selected.
Screenshots
Version Info
NuGet package version: [Microsoft.WinUI 3.0.0-preview3.201113.0]
Additional context