WPF Combobox selectedindex binding

Multi tool use
Multi tool use


WPF Combobox selectedindex binding



I have difficulties binding the selectedindex of a combobox to an object.
This is my code:



(Part of) CustomerClass


public class Customer : INotifyPropertyChanged
{
public int CountryCode
{
get { return _CountryCode; }
set { _CountryCode = value; NotifyPropertyChanged(); }
}
}



2a. (Part of) CustomListItem


<ComboBox x:Name="cboCountryCode" Grid.Column="5" ItemsSource="{Binding}" DisplayMemberPath="LongName" SelectedIndex="{Binding CountryCode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>



2b. (Part of) CustomListItem


public partial class CustomerListItem : UserControl
{
public CustomerListItem()
{
InitializeComponent();
ObservableCollection<CountryCode> Liste = CountryCodes.Instance.List;
cboCountryCode.DataContext = Liste;
}



(Part of) MainPage


<ItemsControl Name="itcCustomers" Style="{StaticResource ItemsControlVirtualizedStyle}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<local:CustomerListItem/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>



The Combobox List Items are shown correctly.
But the selected index is not working at all
See this screenshot




1 Answer
1



I found the problem. I tried to bind the Combobox to two different Datasources. One for the collection and one for the selectedindex. Now I combinde these two Datasources into one class and bound to it, now it works fine






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

lLpwsDyQk,iG,Hx,SUBk7EbuHmeIxGj,U9B7wRwtKO4yghfs
L3 pnWwMZVdsY1 kLe G4 fyqndCQ9

Popular posts from this blog

Rothschild family

Cinema of Italy