Silverlight's XamlWriter!

Hi,

Oh god!, this is my first blog post and this is the second time that I write a complete post and then IE crashes :((

nowadays we hear the sounds of the people who is looking around for a Silverlight's XamlWriter, but there's nothing!

I'm one of the guys who is contributing in Silverlight's Forums (rambler.elf) and I see so many people requested it.

I've decide to create a XamlWriter, and after about 10 hours working it's here! (no no, it's not a ideal XamlWriter, but don't worry, it's not so bad :-) )

a sample Xaml which is created at runtime by XamlWriter :

<Canvas Width="100" Height="150" Opacity="1" RenderTransformOrigin="0,0" Cursor="Default" IsHitTestVisible="True" Visibility="Visible" x:Name="test" Canvas.Left="20" Canvas.Top="0" Canvas.ZIndex="0">
  <Canvas.Background>
    <RadialGradientBrush Center="0.5,0.5" GradientOrigin="0.5,0.5" RadiusX="0.5" RadiusY="0.5" SpreadMethod="Pad" MappingMode="RelativeToBoundingBox" ColorInterpolationMode="SRgbLinearInterpolation" Opacity="1">
      <GradientStop Color="#FFFFFFFF" Offset="0.5" />
      <RadialGradientBrush.Transform>
        <TransformGroup>
          <RotateTransform CenterX="0" CenterY="0" Angle="80" />
        </TransformGroup>
      </RadialGradientBrush.Transform>
    </RadialGradientBrush>
  </Canvas.Background>
  <Canvas.OpacityMask>
    <RadialGradientBrush Center="0.5,0.5" GradientOrigin="0.5,0.5" RadiusX="0.5" RadiusY="0.5" SpreadMethod="Pad" MappingMode="RelativeToBoundingBox" ColorInterpolationMode="SRgbLinearInterpolation" Opacity="1">
      <GradientStop Color="#FFFFFFFF" Offset="0.5" />
    </RadialGradientBrush>
  </Canvas.OpacityMask>
 
    <Ellipse StrokeMiterLimit="10" StrokeThickness="1" StrokeStartLineCap="Flat" StrokeEndLineCap="Flat" StrokeLineJoin="Miter" StrokeDashOffset="0" StrokeDashCap="Flat" Stretch="Fill" Width="20" Height="20" Opacity="1" RenderTransformOrigin="0,0" Cursor="Default" IsHitTestVisible="True" Visibility="Visible" x:Name="el" Canvas.Left="0" Canvas.Top="0" Canvas.ZIndex="0">
      <Ellipse.Fill>
        <SolidColorBrush Color="#FF808080" Opacity="1" />
      </Ellipse.Fill>
    </Ellipse>
    <UserControl1 Width="0" Height="0" Opacity="1" RenderTransformOrigin="0,0" Cursor="Default" IsHitTestVisible="True" Visibility="Visible" Canvas.Left="0" Canvas.Top="0" Canvas.ZIndex="0" />
    <Canvas Width="0" Height="0" Opacity="1" RenderTransformOrigin="0,0" Cursor="Default" IsHitTestVisible="True" Visibility="Visible" Canvas.Left="0" Canvas.Top="0" Canvas.ZIndex="0">
     
        <Rectangle RadiusX="0" RadiusY="0" StrokeMiterLimit="10" StrokeThickness="1" StrokeStartLineCap="Flat" StrokeEndLineCap="Flat" StrokeLineJoin="Miter" StrokeDashOffset="0" StrokeDashCap="Flat" Stretch="Fill" Width="100" Height="100" Opacity="1" RenderTransformOrigin="0,0" Cursor="Default" IsHitTestVisible="True" Visibility="Visible" Canvas.Left="0" Canvas.Top="0" Canvas.ZIndex="0">
          <Rectangle.Fill>
            <SolidColorBrush Color="#FFFFFFFF" Opacity="1" />
          </Rectangle.Fill>
          <Rectangle.RenderTransform>
            <TransformGroup>
              <RotateTransform CenterX="0" CenterY="0" Angle="25" />
            </TransformGroup>
          </Rectangle.RenderTransform>
        </Rectangle>
     
    </Canvas>
 
  <Canvas.RenderTransform>
    <TransformGroup>
      <RotateTransform CenterX="0" CenterY="0" Angle="80" />
    </TransformGroup>
  </Canvas.RenderTransform>
  <Canvas.Triggers>
    <EventTrigger RoutedEvent="Canvas.Loaded">
      <BeginStoryboard>
        <Storyboard>
          <DoubleAnimation From="0" To="10" AutoReverse="False" BeginTime="00:00:00" Duration="00:00:00" SpeedRatio="1" FillBehavior="HoldEnd" RepeatBehavior="00:00:00" Storyboard.TargetName="el" Storyboard.TargetProperty="Opacity" />
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Canvas.Triggers>
  <Canvas.Resources>
    <Storyboard AutoReverse="False" BeginTime="00:00:00" Duration="00:00:00" SpeedRatio="1" FillBehavior="HoldEnd" RepeatBehavior="00:00:00" x:Name="testSB">
     
        <DoubleAnimationUsingKeyFrames AutoReverse="False" BeginTime="00:00:00" Duration="00:00:00" SpeedRatio="1" FillBehavior="HoldEnd" RepeatBehavior="00:00:00">
          <DiscreteDoubleKeyFrame Value="5" KeyTime="00:00:00.5000000" />
        </DoubleAnimationUsingKeyFrames>
     
    </Storyboard>
  </Canvas.Resources>
</Canvas>

Limitations :

  1. custom prefixes is not suported. for example : <uc:UserControl1 ... will be resolved to <UserControl1
  2. due to silverlight's limitation for dependency properties, the ones that are not in the control's hirarechy except Canvas.Left, Canvas.Top, Canvas.ZIndex, Storyboard.TargetName and Storyboard.TargetProperty, are not supported.

Project :

please use the following link to download the project :

http://weblogs.asp.net/blogs/mehrantoosi/Silverlight/XAMLTools.zip

Thanks

-M

Attachment: XAMLTools.zip
Published Monday, March 3, 2008 7:17 AM by rambler_elf
Filed under: ,

Comments

# re: Silverlight's XamlWriter!

Monday, March 24, 2008 6:00 AM by Justin-Josef Angel [MVP]

Hi,

I've sent some traffic your way. Do you plan publishing a SL 2.0 version of the XamlWriter class?

# re: Silverlight's XamlWriter!

Tuesday, March 25, 2008 5:41 AM by rambler_elf

Hi Justin,

Yes I've planned to rewrite the class for SL 2.0.

do you wanna help me? :-)

Thanks

-Mehran

# re: Silverlight's XamlWriter!

Wednesday, April 9, 2008 12:39 PM by Dave Lowther

Mehran,

Great work here. I am looking foward to a SL2B1 release. In the meantime, I pulled the code into a SL2B1 class and it mostly worked. I had to hardcode a "return true" on line 17 of TypeValidator.cs and I changed line 166 of XamlWriter.cs to read:

if (val != null && val.GetType().ToString() == "System.Windows.DependencyObject")

Then I am able to at least get somewhere.

Thanks and I hope that helps you a bit!

Dave

# re: Silverlight's XamlWriter!

Thursday, April 10, 2008 9:35 AM by rambler_elf

Hi Dave,

Thanks for your help. ;)

I'm experiencing busy days at office, but I'm looking forward to take my time for rewriting the class.

Thanks again.

-Mehran

# re: Silverlight's XamlWriter!

Tuesday, August 19, 2008 3:03 PM by Rez

So, how does one include namespaces?

# re: Silverlight's XamlWriter!

Tuesday, October 7, 2008 12:57 AM by Anan

Hi

Waiting badly for your SL 2.0 Beta 2 version of XAML writer....

# re: Silverlight's XamlWriter!

Wednesday, December 10, 2008 4:20 PM by Abhijeet P

Are you looking to start a codeplex project. If so I'd be interested. Contact me at

abhidotnetATgmailDOTCOM

PS - Replace AT with an @

# re: Silverlight's XamlWriter!

Monday, September 28, 2009 5:56 AM by haifeng

对不起,我英文很差,请原谅!

我这里总是出错This Type is not supported by Xaml Writer

我现在用的是3.0中文版,RegexOptions接口没有Compiled了, 所以只有将getSilverlightCompatibleXaml中的RegexOptions改了,但是改成什么都是上边的那个错误,用不了。你能不能说下是什么原因?我的Email:

xiehaifeng666@163.com

# re: Silverlight's XamlWriter!

Friday, June 11, 2010 11:09 PM by Bobin

Hi,your xamlwriter is good.but it don't work with textbox,image.I hope you will improve it.

Thanks for your xamlwriter.

# re: Silverlight's XamlWriter!

Tuesday, March 26, 2013 2:59 AM by Schubert

What's up, just wanted to say, I loved this blog post. It was helpful. Keep on posting!

# re: Silverlight's XamlWriter!

Wednesday, March 27, 2013 7:14 PM by Schell

Unquestionably believe that which you stated.

Your favorite justification seemed to be on the internet the easiest

thing to be aware of. I say to you, I certainly get irked while people think about worries that they just do not know about.

You managed to hit the nail upon the top and also defined out the whole thing without

having side effect , people could take a signal.

Will probably be back to get more. Thanks

# re: Silverlight's XamlWriter!

Sunday, March 31, 2013 6:11 AM by Castle

Excellent blog you have got here.. It's hard to find quality writing like yours nowadays. I honestly appreciate people like you! Take care!!

# re: Silverlight's XamlWriter!

Wednesday, April 3, 2013 10:42 AM by Buford

Good day! Do you use Twitter? I'd like to follow you if that would be okay. I'm definitely enjoying your

blog and look forward to new posts.

# re: Silverlight's XamlWriter!

Wednesday, April 3, 2013 7:58 PM by Hollins

Truly when someone doesn't know afterward its up to other people that they will assist, so here it occurs.

# re: Silverlight's XamlWriter!

Tuesday, April 9, 2013 1:04 PM by Albers

It's really a great and helpful piece of info. I am satisfied that you simply shared this helpful info with us. Please stay us up to date like this. Thanks for sharing.

# re: Silverlight's XamlWriter!

Sunday, April 14, 2013 2:00 AM by Mckinney

Greetings! Quick question that's completely off topic. Do you know how to make your site mobile friendly? My web site looks weird when viewing from my iphone 4. I'm trying to find a template

or plugin that might be able to correct this problem.

If you have any recommendations, please share. Cheers!

# re: Silverlight's XamlWriter!

Saturday, April 20, 2013 10:34 AM by Meacham

I truly love your website.. Very nice colors & theme.

Did you build this website yourself? Please reply

back as I'm planning to create my very own site and would love to learn where you got this from or exactly what the theme is named. Appreciate it!