I am building some animations through code and serialize them to xaml-files
with the XAMLWriter.
This all works perfect as long as the element the animation targets has a
own name-property. I can assign a name, register it with the canvas:

shp.Name = "shp1";
canvas.RegisterName(shp.Name, shp);
Storyboard.SetTargetProperty(timeline, new
Storyboard.SetTargetName(timeline, shp.Name);

This shape gets animated if I open the XAML.

When I want to animate the color:

SolidColorBrush b = shp.Fill;
Storyboard.SetTargetProperty(timeline, new PropertyPath(Canvas.LeftProperty));
Storyboard.SetTargetName(timeline, "brush1");

This does not work. Looking in the resulting XAML I see there is no name
assigned to the brush. If I add a name (x:Name="brush1") and add the
respective x-namespace
) I can get the color animation to work.

As a equivalent coding technique is used in a sample from MS
(http://msdn2.microsoft.com/en-us/library/aa970561.aspx) I suppose this will
work if I show the results directly and the registered name gets lost during
serialization to XAML. Is there anything I have to do with namespaces or is
there now way of serializing those names?