Just a follow-up:
I wrote a simple conversion app to make the generated xaml attributes Expression Blend friendly
After working with the objects exported to xml, I found myself not needing Blend
Nicely done!
(Hope to see your WPF only products made available to Silverlight...)
ttiggemann, May I ask you what have you done to make the xaml Blend friendly.
I would like to add this to the my reader products, so there would not be a need for custom convertion applications.
As stated, not that robust - could probably be optimized a tad
I've condensed it a bit for this post
Code:
using System.IO;
using System.Linq;
using System.Xml.Linq;
namespace ConvertWpfToSL
{
class Program
{
static void Main(string[] args)
{
var testFile = File.OpenText(args[0]);
var oldXmlSnippet = testFile.ReadToEnd();
var newXmlSnippet = WpfXaml.Convert(oldXmlSnippet).ToString();
}
}
public class WpfXaml
{
const string CCanvas = "Canvas";
const string CMatrix = "Matrix";
const string CRenderTransform = "RenderTransform";
const string CMatrixTransform = "MatrixTransform";
const string CCanvasRenderTransform = CCanvas + "." + CRenderTransform;
public static XElement Convert(string xmlSnippet)
{
var doc = XDocument.Parse(xmlSnippet);
var root = doc.Elements().ElementAt(0);
return Convert(root);
}
private static XElement Convert(XElement el)
{
var canvasElements = el.Elements(el.Name.Namespace + CCanvas);
var attr = el.Attribute(CRenderTransform);
if (attr != null)
{
var newCanvasElement = new XElement(CCanvasRenderTransform);
var newMatrixTransform = new XElement(CMatrixTransform);
newMatrixTransform.SetAttributeValue(CMatrix, attr.Value);
newCanvasElement.Add(newMatrixTransform);
el.AddFirst(newCanvasElement);
attr.Remove();
}
foreach (var elem in canvasElements)
Convert(elem);
return el;
}
}
}
ttiggemann, thank you for sharing this with us.
I will add an option to ViewerSvg, Paste2Xaml and GetXaml method in reader libraries to provide xaml that will be valid in Expression Blend.
Just FYI:
VS2010 is not happy either:
"Unknown element: Brush. [Line: 1 Position: 93]
at MS.Internal.XcpImports.CreateFromXaml(String xamlString, Boolean createNamescope, Boolean requireDefaultNamespace, Boolean allowEventHandlers, Boolean expandTemplatesDuringParse)
at Microsoft.Expression.Platform.Silverlight.TypeConverters.ConvertUsingXamlReaderConverter`1.ConvertFromStringInternal(String value, IFormatProvider provider)
at Microsoft.Expression.Platform.Silverlight.TypeConverters.ConvertToFromStringConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at System.ComponentModel.TypeConverter.ConvertFromInvariantString(String text)
at Microsoft.Expression.DesignModel.InstanceBuilders.ClrObjectInstanceBuilder.InstantiateTargetType(IInstanceBuilderContext context, ViewNode viewNode)"
Is there an ETA of when your changes will be available?
Thank you!
Hm, this looks very critical.
I will try to prepare updates until the end of this week.
Finally got the chance to try your updates in v2.2
Looks great, works great!
"Add default namespaces" is certainly a timesaver
A couple of items on my "wish list":
The ability to name the top level node
The ability to specify a background color (mouse events are ignored if no background)
Thank you!