Noobie Questions

Topics: Getting Started
Oct 26, 2012 at 12:53 AM

I've been trying to learn Caliburn Micro.

I've looked everywhere but I don't see how to wire up such things such as having to call subroutines in a visual element from a VM.

For example, how do I call Listview.SelectedItems.clear() from the View Model class?

Thanks for any help!


Oct 26, 2012 at 8:28 PM

If you are inheriting your view model from Screen then you should have access to the view via the Views property or GetView(object) method.  You can then cast the view to the appropriate type and access the ListView from there.

var view = GetView(null) as MyView;

I am a bit of a Caliburn.Micro newb myself, so if anyone out there has a better way please chime in.

On a side note:

There are plenty of folks that would argue that accessing controls on the view from the view model is not MVVM, I'll leave that decision to you as it was not part of your question.  But if the SelectedItems collection is your primary concern right now, and wish to address it in a more MVVM-ish fashion, there are a handful of articles on the web to accomplish this.  One of my projects did do this at one point and if I remember correctly our solution involved attached properties.  Here is a link to potential food for thought:

Oct 27, 2012 at 3:15 AM

Great! Thanks for your help!