Caliburn.Micro : How to bind a specific Item of Conductor.Collection.AllActive to a ContentControl

前端 未结 3 995
轻奢々
轻奢々 2021-01-21 16:46

My goal is to have 4 different active ViewModels displayed in a grid on the ShellView. The issue is that I have not been able to figure out how to wire up a ContentControl to a

3条回答
  •  半阙折子戏
    2021-01-21 16:58

    The Caliburn concept of Context is used to map a view model to multiple views, usually through conventions and mapping namespaces. In this case, however, each of your view models maps to exactly one view. Hence you don't need to / should not provide a context.

    Second, your view model binding cannot be resolved without exposing them as public props (as @Jack suggested). Ironically, the binding you used for Context is the right one for the view model binding.

    Replacing

    
    

    With

    
    

    Should do the trick.

    Given the number of items is fixed it's better to follow @Jack's approach and reference the view models in a strongly typed fashion. Rather than relying on their index in the items collection. You can use either:

    
    

    Or

    
    

    Which are synonymous.

    As you noticed the Caliburn Conductor really shines when used in combination with ItemControl. You typically don't need to have strongly typed references to the each of the Items then. That doesn't mean you can't use the conductor as you did, you still enjoy all the benefits of the managed lifecycle.

提交回复
热议问题