I have been using Caliburn.Micro's binding via convention in Silverlight 5 and am loving it. Here is an example property from a ViewModel:
private String _vmStringProp = ""; public String VmStringProp {     get     {         return _vmStringProp;     }      set     {         _vmStringProp = value;         NotifyOfPropertyChange(() => VmStringProp);     } }   This property is bound in the View just by naming:
<TextBox x:Name="VmStringProp" />   This works great. But if I change it to a TextBlock or Lable (example below) an exception is thrown.
<sdk:Label x:Name="VmStringProp" />   It works fine if you change it to bind like normal Silverlight but I would rather keep consistent throughout the project instead of having some bound via convention and others explicitly bound depending on what type of control. Does anyone know why I can't bind via convention with Labels and TextBlocks?
Answer: 1
Caliburn.Micro comes with a set of default conventions for WPF/SL/WP7 but obviously not for every existing control, so the Silverlight sdk:Label is also missing. 
You can find the built in conventions at the end of this article and a lots of info how conventions work.
Luckily it is very easy to add a new convetions just add the following code into your Bootstrapper's contructor:
public MyBootstrapper() {     ConventionManager         .AddElementConvention<Label>(Label.ContentProperty,                                      "Content",                                      "DataContextChanged");   }  by : nemesvhttp://stackoverflow.com/users/872395
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog