ComboBox Binding Problem

Topics: Bugs
Apr 29, 2013 at 11:12 AM
Hi!

I'm trying to use a ComboBox but the Binding isn't working properly. The comboboxes get filled, but only with the message: "Cannot find view for System.String." (I also tried with string instead of String). Also, the selectedFilter property gets called when I change the combobox selected item.

Code:

View.xaml
<ComboBox x:Name="Filters"
                    Grid.Column="0"
                    HorizontalAlignment="Left"
                    Margin="5"
                    Width="290"/>
ViewModel.cs
private const String all = "All";
private const String lastMonth = "Last Month";
private const String lastWeek = "Last Week";
private const String yesterday = "Yesterday";

private String[] filtersComboValues = new String[] { all, lastMonth, lastWeek, yesterday };

public DashboardViewModel(INavigationService navigationService) : base(navigationService)
{
    this.navigationService = navigationService;
    this.dataService = new DataService();
    (...)
    this.Filters = new BindableCollection<string>(filtersComboValues);
    selectedFilter = filtersComboValues[0];
}

private BindableCollection<String> filters;     
public BindableCollection<String> Filters
{
    get { return this.filters; }
    set { this.filters = value; this.NotifyOfPropertyChange(() => this.Filters); }
}

private String selectedFilter;
public String SelectedFilter
{
    get { return selectedFilter; }
    set { selectedFilter = value; this.NotifyOfPropertyChange(() => this.SelectedFilter); }
}
May 13, 2013 at 4:23 PM
I am having a similar issue. Mine says it cannot find view for "my.model".

Did you figure it out?
May 14, 2013 at 8:19 AM
Please see the following question on StackOverflow as it explains the problem, essentially you need to add in an items template and bind to that. The link has an example.
May 31, 2013 at 3:03 AM
Has something changed related to this in between 1.5 and previous version of CM? When i tried the above I could see it working without defining any data template for the combo box item (i could not compile the above though as we are passing filtersComboValues to BindableCollection which it does not accept). But otherwise it worked ok for me

filters = new BindableCollection<String>() { };
        filters.Add(filtersComboValues[0]);
        filters.Add(filtersComboValues[1]);
        filters.Add(filtersComboValues[2]);