Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Find out the new features and enhancements added in Silverlight 5.

Moderators

Top Categories · View All
Controls Enhancements 11
Text Enhancements 3
Trusted Applications Features 2

Browse by Tags · View All
Silverlight 5 16
Controls 11
Text Enhancements 3
RichTextBlockOverflow 2
RichTextblock 2
CharacterSpacing 1
UpdateSourceTrigger 1
PropertyChanged 1
Out Of Browser Features 1
P/Invoke 1
Multiple Windows 1
Trusted Applications 1
Styles 1
Relative Source Binding 1
PivotViewer 1
Custom Markup Extensions 1
Implicit Data Templates 1
Data Templates 1
Debugging 1
Debugging in XAML 1

Browse by Release · View All
All 15
RC 1

What is new in Silverlight 5

Silverlight 5 - Custom Markup Extensions to create our own markup extensions like binding,Static Resource etc

Dec 17 2011 4:57AM by Ramireddy   

We often use In-Built markup extensions such as Binding, Static Resource, Template Binding and Relative Source. We will use these markup extensions with curly braces {}. Now in Silverlight 5, we can also write our own Custom Markup Extensions.

Implementing custom markup extension:

  1. Create a class, which should inherit from “MarkupExtension" or the class should implement the interface “IMarkUpExtension”. Class Name should end with “Extension”
  2. “ImarkUpExtension” has a method “ProvideValue. Our Custom Markup Extension should implement this method. Return value of this method will be assigned to the property, for which custom markup extension has been binded.
  3. We can pass parameters to this class by using public properties in class. We can also get the name of the control and property of control that has been binded by using “ServiceProvider”, which will be in default passed as parameter to “Provide Value” method.

Getting ControlName and Control Property, that Markup extensions is binded

  IProvideValueTarget ipValueTarget = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;
  FrameworkElement targetElement = ipValueTarget.TargetObject as FrameworkElement;                   
  PropertyInfo vPropertyInfo = ipValueTarget.TargetProperty as PropertyInfo;
  // If it’s a dependency property,cast TargetProperty to dependency property instead of propertyinfo

Example:

public class CustomMarkupExtension :MarkupExtension
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public CustomMarkupExtension()
        {
        }        
        public override object ProvideValue(IServiceProvider serviceProvider)
        {            
            return Convert.ToString(FirstName + " "  + LastName);
        }        
    }

xmlns:local="clr-namespace:Sl5Features"
<TextBlock Text="{local:CustomMarkupExtension FirstName=Rami,LastName=Reddy}" />

Read More Have you written a blog post or article related to this feature and want to get them added here? Read More...
Category : Controls Enhancements
Release : All
Tags : Silverlight 5,Controls,Custom Markup Extensions


Ramireddy
2 · 41% · 12972
2



Submit

Your Comment


Sign Up or Login to post a comment.

"Silverlight 5 - Custom Markup Extensions to create our own markup extensions like binding,Static Resource etc" rated 5 out of 5 by 2 readers
Silverlight 5 - Custom Markup Extensions to create our own markup extensions like binding,Static Resource etc , 5.0 out of 5 based on 2 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]