Combobox SelectionChanged handling using ViewModel #17735
-
Hi I'm trying to update the value of my combobox when its selection changes using my ViewModel, unsure how it should be done The combox is populated when the page starts from my Have the below in my Model folder as
My SettingsViewModel.cs
A method in my
my xaml in my
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hey @ashah7, I think you are mostly on the correct route, I just updated your code a bit to use the <ComboBox x:Name="comboEstablishmentSelection"
Grid.Row="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="14"
Margin="0,0,0,0"
ItemsSource="{Binding EstablishmentsOptions}"
DisplayMemberPath="description"
SelectedValuePath="establishid"
SelectedValue="{Binding RequestUserOptions.UserOptions.Establishid, Mode=TwoWay}" /> private int? establishid;
public int? Establishid
{
get => establishid;
set
{
// Work with the selected item as needed
SetProperty(ref establishid, value);
}
} Now the value in the Establishid should update when the selected item in the ComboBox is changed. Let me know if those changes work for you. |
Beta Was this translation helpful? Give feedback.
Hey @ashah7,
I think you are mostly on the correct route, I just updated your code a bit to use the
TwoWay
binding onSelectedValue
.