public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (ElementStartRecord)((BamlBlockNode)node).Header; var doc = new BamlElement(node); var elemType = ctx.ResolveType(record.TypeId); doc.Xaml = new XElement(elemType.ToXName(ctx)); doc.Xaml.Element.AddAnnotation(elemType); parent.Xaml.Element.Add(doc.Xaml.Element); HandlerMap.ProcessChildren(ctx, (BamlBlockNode)node, doc); var key = node.Annotation as XamlResourceKey; if (key != null && key.KeyNode.Record != node.Record) { var handler = (IDeferHandler)HandlerMap.LookupHandler(key.KeyNode.Record.Type); var keyElem = handler.TranslateDefer(ctx, key.KeyNode, doc); doc.Children.Add(keyElem); keyElem.Parent = doc; } elemType.ResolveNamespace(doc.Xaml, ctx); doc.Xaml.Element.Name = elemType.ToXName(ctx); return(doc); }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (PropertyWithStaticResourceIdRecord)((BamlRecordNode)node).Record; var doc = new BamlElement(node); var elemAttr = ctx.ResolveProperty(record.AttributeId); doc.Xaml = new XElement(elemAttr.ToXName(ctx, null)); doc.Xaml.Element.AddAnnotation(elemAttr); parent.Xaml.Element.Add(doc.Xaml.Element); BamlNode found = node; XamlResourceKey key; do { key = XamlResourceKey.FindKeyInAncestors(found.Parent, out found); } while (key != null && record.StaticResourceId >= key.StaticResources.Count); if (key == null) { throw new Exception("Cannot find StaticResource @" + node.Record.Position); } var resNode = key.StaticResources[record.StaticResourceId]; var handler = (IDeferHandler)HandlerMap.LookupHandler(resNode.Type); var resElem = handler.TranslateDefer(ctx, resNode, doc); doc.Children.Add(resElem); resElem.Parent = doc; elemAttr.DeclaringType.ResolveNamespace(doc.Xaml, ctx); doc.Xaml.Element.Name = elemAttr.ToXName(ctx, null); return(doc); }