Reader Level:

Custom Markup Extensions in Silverlight 5: Part 2

By Mahadesh Mahalingappa on Aug 21, 2011
In this article we are going to continue to learn about the Custom Markup Extensions in Silverlight 5 .

In this post we will see how we can pass the parameters using Custom Markup Extensions .

Now that we have a understanding of how Custom Markup Extensions work in Silverlight lets quickly get into the code .

I modify my class FirstCME as shown as below :

public class FirstCME : IMarkupExtension<string>
        public object value1 { get; set; }

        public object value2 { get; set; }

        public string ProvideValue(IServiceProvider serviceProvider)
            double _val1 = Convert.ToDouble(value1);
            double _val2 = Convert.ToDouble(value2);

            return (_val1 + _val2).ToString();

Go ahead and modify the xaml to pass the value to the parameters . It would look like below :

<UserControl x:Class="SLCustomMarkup.MainPage"
    d:DesignHeight="300" d:DesignWidth

    <Grid x:Name="LayoutRoot" Background="White">
        <TextBlock Text="{local:FirstCME value1=10,value2=20}"></TextBlock>

Lets give it a run and see the output :


The above xaml code could be modified as shown below : It would still work the same way . Here we pass the parameters in a Angular Bracket < > Format .


Lets now give it a run :


In the next post on Custom Markup Extensions we will see what are the advantages of Custom Markup Extensions . Thanks . Happy Coding.

Mahadesh Mahalingappa
Mahadesh Mahalingappa

I am a C# developer interested in coding in Latest Microsoft Technolgies like Silverlight , WPF and WCF. I am very much interested in advanced concepts like MEF , MVVM, AOP .