I have a Combobox and it has as itemssource a struct with some properties, and I have a viewModel that has some properties of this struct, I want to know if there is a way to make the combobox set the parameters of the viewmodel equal to certain parameters of the selected item.
Of course, I could create another property of my VM and it will be of the type of that struct, so I would put the selecteditem of the combobox equal to this new property, unfortunately in this specific scenario I can not do that.
<ComboBox ItemsSource="{Binding Source={StaticResource estados}, Path=Siglas}"
SelectedItem="{Binding Emit.endereco.SiglaUF, Mode=TwoWay}"
Header="Estado" />
<ComboBox ItemsSource="{Binding Emit.endereco.SiglaUF, Converter={StaticResource obterMunicipios}}"
SelectedItem="{Binding Path=ConjuntoMunicipio, Mode=TwoWay}"
DisplayMemberPath="Nome"
Header="Município" />
public Municipio ConjuntoMunicipio
{
get => Municipios.Get(Emit.endereco.SiglaUF).FirstOrDefault(x => x.Codigo == Emit.endereco.CodigoMunicipio);
set
{
Emit.endereco.NomeMunicipio = value?.Nome;
Emit.endereco.CodigoMunicipio = value?.Codigo ?? 0;
}
}