Tuesday, April 26, 2011

A lovely feature of Silverlight 5 beta

Just saw this on Mike Taulty's blog. The ability to create your own custom markup extensions. The thing I like the most about this is being able to abreviate the common binding syntax that I seem to be using a lot:

Definition:

public class StandardTwoWayBindingExtension : Binding  
{  
  public StandardTwoWayBindingExtension()  
  {  
    this.ValidatesOnNotifyDataErrors = true;  
    this.NotifyOnValidationError = true;  
    this.Mode = BindingMode.TwoWay;        
  }  
}  


Usage:

<Grid  
  x:Name="LayoutRoot">  
  <Grid.DataContext>  
    <local:DataObject />  
  </Grid.DataContext>  
  <TextBox  
    Text="{local:StandardTwoWayBinding Path=SomeProperty}" />  
</Grid> 


Head on over to the post to see it in action.
Enjoy!

No comments:

Post a Comment