开发者

Does Caliburn require an element convention for a given object to map a ViewModel instance of it to a View instance?

I'm trying to map a Canvas object in my ViewModel to a Canvas object in my View.

However I get a "CompositionException was unhandled by us开发者_StackOverflower code" error when I run. Commenting out my Canvas object in the ViewModel prevents the error, so I'm guessing Caliburn is trying to map it and raising the error.


A Canvas object in your ViewModel to a Canvas object in your View?

I don't think Caliburn will do that. Caliburn is expecting you to map your properties/methods to controls on the page.

So:ViewModel

public MyModel Models
{
    get{return _values;}
    set{ 
         _value=values;
         RaisePropertyChangedImmediately("Models");
       }
}

public MyModel SelectedModel
{
    get{return _value;}
    set{ 
         _value=value;
         RaisePropertyChangedImmediately("SelectedModel");
       }
}

View:

<ListBox x:Name="Models/>

What this code does is links the SelectedModel up to the "SelectedItem" property of the ListBox, the Models property up to the "ItemsSource" property and wires in the CheckedChange event so that the SelectedItem is changed when the user clicks on it.

There's a great documentation section in Caliburn, it's well worth going through his examples: Caliburn Micro Docs

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜