I have a combobox for selecting screen resolution width x height . For example :
1024×768 (Standard)
800×699 (Standard)
1500×900 (Wide)
I have a MutliValueConverter to convert the resolution string to a view model width and height member (in the ConvertBack method of the converter ) , but the Convert method just return null.
in the xaml for the combobox I have
<ComboBox.Text>
<MultiBinding Converter="{StaticResource resolutionConverter}">
<Binding Path="GameWidth"/>
<Binding Path="GameHeight"/>
</MultiBinding>
</ComboBox.Text>
When I click to select a value in the combobox , the combobox will fall back to selecting nothing . Why is that ?
I do not think you are supposed to do anything like that, normally you would just set the
ItemsSourceto your collection of viewmodels and theDisplayMemberPathto the name of the property which holds the display string and that should be about it. The selected item will then be the view model.If the viewmodels have no display string you could bind to a dictionary of
<string,ViewModel>, then you need to set theDisplayMemberPathtoKeyand theSelectedValuePathtoValue, then the selected VM will be in theSelectedValueproperty.(Another option to generate the displayed string for the items is using the
ItemTemplate. the VM’s should then of course have suitable properties which can be used in it. This will not work well together withIsEditablethough)