4

My VM has a property of my Model, Authorization, which has a property of ActiveService.

public Authorization Authorization
    {
        get
        {
            return this.authorization;
        }
        set
        {
            this.authorization = value;
            NotifyOfPropertyChange();
        }
    }

I created an additional property on my ViewModel, called Services to populate the dropdown with:

    public IList<Service> Services
    {
        get { return services; }
        set
        {
            services = value;
            NotifyOfPropertyChange();
        }
    }

My View has a combobox control named Services. My understanding of Caliburn and it's conventions is that this should work. However it doesn't display my items correctly. It has the right number of items in the list but it only shows "Cannot find view for Models.Service"

Any help on what I'm doing wrong?

EDIT

So what I tried now is this; I manually set the DisplayMemberPath Binding like so:

DisplayMemberPath="{Binding Authorization_ActiveService_Description}"

and then I added an Override to my Service object on ToString() like so:

        public override string ToString()
    {
        return string.Format("{0}", this.Description);
    }

This works, in that it now displays my Description in the DropDown. I'm a little confused though. I was able to remove the _Description and it works the same. If I remove the Override it doesn't work at all.

Why doesn't it do the deep binding to my Description Property?

Refracted Paladin
  • 12,096
  • 33
  • 123
  • 233
  • http://stackoverflow.com/questions/11083314/cannot-find-view-for-viewmodel this is similar to my problem but there was never a resolution... – Refracted Paladin May 13 '13 at 16:57
  • Umm... I see no reason why simple `SelectedItem` binding wouldn't work here, but maybe I'm missing something in the picture. – Patryk Ćwiek May 13 '13 at 20:16
  • @Trustme-I'maDoctor Could you elaborate on what you mean? New to WPF, MVVM, and Caliburn.Micro so the answer may simply lie in my ignorance. – Refracted Paladin May 14 '13 at 01:36

1 Answers1

4

By default, for an ItemsControl (such as a ComboBox), if the ItemTemplate has not been set, then Caliburn.Micro will set the ItemTemplate to a default implementation which uses a ContentControl for view injection, as it assumes that each item in your bound collection is a view model, and you want to define a view to bind to that view model.

If you don't want to define a view, but would rather define the ItemTemplate in the ComboBox markup, then you can, e.g:

<ComboBox x:Name="Services">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <TextBox Text="{Binding Name}" />
                <TextBox Text="{Binding AnotherServiceProperty}" />                  
            </StackPanel>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>
M.kazem Akhgary
  • 18,645
  • 8
  • 57
  • 118
devdigital
  • 34,151
  • 9
  • 98
  • 120
  • Ah, my ignorance may be at play here. It's not that I don't WANT to define a view but rather that I didn't know I needed to. New to WPF, MVVM, Caliburn, the whole she-bang. How do I do comboboxes in this scenario the "default" way? I need a View of what I want shown in the dropdown? Is there a Naming Convention that ties them together? – Refracted Paladin May 14 '13 at 00:44
  • It might be that for a simple ComboBox, Caliburn.Micro's default behaviour is overkill for your needs, unless you want every item to use a full blown view. You could also set DisplayMemberPath if you want just a simple display string. As for the convention, if you have a view model called ItemViewModel sitting for example in a ViewModels folder, then CM will look for an ItemView in a sibling Views folder. – devdigital May 14 '13 at 07:40