Question

I want to bind against a list of IScreens in my ShellViewModel

    ...

    public ObservableCollection<IScreen> RightWindowCommands
    {
        get
        {
            return this.rightWindowCommands;
        }
        set
        {
            this.rightWindowCommands = value;
            this.NotifyOfPropertyChange(() => this.RightWindowCommands);
        }
    }

    ...

and use the list of screens in a Mahapps.Metro Window as WindowCommands

<controls:MetroWindow.RightWindowCommands>
    <controls:WindowCommands ItemsSource="{Binding RightWindowCommands}" >
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <ContentControl cal:View.Model="{Binding .}" />
            </DataTemplate>
        </ItemsControl.ItemTemplate>           
    </controls:WindowCommands>
</controls:MetroWindow.RightWindowCommands>

It seems it doesn't work this way (the IScreen is printed out as text instead of resolving the view) but it works if I put this into a ListBox instead of MetroWindow.WindowCommands inside the window itself. It seems that Caliburn.Micro does not search this visual tree.

Any suggestions how to force caliburn to parse this to?

Update:

Log:Debug: Neither XML 'id' nor 'name' specified - using generated object name [Shells.MyViewModel#3FB40AD] Log:Info: Action Convention Not Applied: No actionable element for get_Session. Log:Info: Action Convention Not Applied: No actionable element for get_Session. Log:Info: Action Convention Not Applied: No actionable element for Handle. ...

But nothing about resolving a view that did not work or trying to resolve a view.

Was it helpful?

Solution

I solved the problem with a workaround (that even looks more decoupled) using a ContentControl instead with a separate ViewModel instead of using the DataTemplate. DataTemplate works when it is used within the ContentControl's Content:

<controls:MetroWindow.RightWindowCommands>
    <controls:WindowCommands>
        <controls:MetroContentControl cal:View.Model="{Binding MySeparateViewModel}" />
    </controls:WindowCommands>
</controls:MetroWindow.RightWindowCommands>

The cal:View.Model looks onto a property of my ShellViewModel. Hope this helps if someone else has the same problem to solve.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top