/// <summary> /// Loads XAML from a stream. /// </summary> /// <param name="stream">The stream containing the XAML.</param> /// <param name="localAssembly">Default assembly for clr-namespace</param> /// <param name="rootInstance"> /// The optional instance into which the XAML should be loaded. /// </param> /// <param name="uri">The URI of the XAML</param> /// <returns>The loaded object.</returns> public object Load(Stream stream, Assembly localAssembly, object rootInstance = null, Uri uri = null) { var readerSettings = new XamlXmlReaderSettings() { BaseUri = uri, LocalAssembly = localAssembly, ProvideLineInfo = true, }; var context = IsDesignMode ? AvaloniaXamlSchemaContext.DesignInstance : AvaloniaXamlSchemaContext.Instance; var reader = new XamlXmlReader(stream, context, readerSettings); object result = LoadFromReader( reader, AvaloniaXamlContext.For(readerSettings, rootInstance)); var topLevel = result as TopLevel; if (topLevel != null) { DelayedBinding.ApplyBindings(topLevel); } return(result); }
internal static object LoadFromReader(XamlReader reader, AvaloniaXamlContext context = null) { var writer = AvaloniaXamlObjectWriter.Create( reader.SchemaContext, context); XamlServices.Transform(reader, writer); writer.ApplyAllDelayedProperties(); return(writer.Result); }
/// <summary> /// Loads XAML from a stream. /// </summary> /// <param name="stream">The stream containing the XAML.</param> /// <param name="rootInstance"> /// The optional instance into which the XAML should be loaded. /// </param> /// <param name="uri">The URI of the XAML</param> /// <returns>The loaded object.</returns> public object Load(Stream stream, object rootInstance = null, Uri uri = null) { var readerSettings = new XamlXmlReaderSettings() { BaseUri = uri, LocalAssembly = rootInstance?.GetType().GetTypeInfo().Assembly }; var reader = new XamlXmlReader(stream, _context, readerSettings); object result = LoadFromReader( reader, AvaloniaXamlContext.For(readerSettings, rootInstance)); var topLevel = result as TopLevel; if (topLevel != null) { DelayedBinding.ApplyBindings(topLevel); } return(result); }
public AvaloniaXamlObjectWriterSettings(XamlObjectWriterSettings settings, AvaloniaXamlContext context) : base(settings) { Context = context; }
public static XamlObjectWriterSettings WithContext(this XamlObjectWriterSettings settings, AvaloniaXamlContext context) { return(new AvaloniaXamlObjectWriterSettings(settings, context)); }