private ParseException ( string message ) : System.Windows.Markup.XamlParseException | ||
message | string | |
return | System.Windows.Markup.XamlParseException |
private static unsafe IntPtr ParseTemplate (Value *context_ptr, string resource_base, IntPtr surface, IntPtr binding_source, string xaml, ref MoonError error) { XamlContext context = Value.ToObject (typeof (XamlContext), context_ptr) as XamlContext; var parser = new XamlParser (context); var source = NativeDependencyObjectHelper.FromIntPtr (binding_source); if (source == null) { error = new MoonError (parser.ParseException ("Attempting to parse a template with an invalid binding source.")); return IntPtr.Zero; } FrameworkElement fwe = source as FrameworkElement; if (fwe == null) { error = new MoonError (parser.ParseException ("Only FrameworkElements can be used as TemplateBinding sources.")); return IntPtr.Zero; } context.IsExpandingTemplate = true; context.TemplateBindingSource = fwe; INativeEventObjectWrapper dob = null; try { dob = parser.ParseString (xaml) as INativeEventObjectWrapper; } catch (Exception e) { error = new MoonError (e); return IntPtr.Zero; } if (dob == null) { error = new MoonError (parser.ParseException ("Unable to parse template item.")); return IntPtr.Zero; } return dob.NativeHandle; }
private static unsafe IntPtr ParseTemplate (Value *context_ptr, IntPtr resource_base, IntPtr surface, IntPtr binding_source, string xaml, ref MoonError error) { XamlContext context = Value.ToObject (typeof (XamlContext), context_ptr) as XamlContext; var parser = new XamlParser (context) { ResourceBase = UriHelper.FromNativeUri (resource_base), }; FrameworkElement fwe = null; var source = NativeDependencyObjectHelper.FromIntPtr (binding_source); if (source != null) { fwe = source as FrameworkElement; if (fwe == null) { error = new MoonError (parser.ParseException ("Only FrameworkElements can be used as TemplateBinding sources.")); return IntPtr.Zero; } } Log ("222222 ParseTemplateElement {0}", source); Log ("{0}", xaml); context.IsExpandingTemplate = true; context.TemplateOwner = source as DependencyObject; context.TemplateBindingSource = fwe; parser.HydrateObject = context.Template; INativeEventObjectWrapper dob = null; try { FrameworkTemplate template = parser.Parse (context.Node) as FrameworkTemplate; if (template != null) { dob = template.Content as INativeEventObjectWrapper; template.Content = null; } // No errors, but the template was just empty. if (dob == null) return IntPtr.Zero; } catch (Exception e) { error = new MoonError (e); return IntPtr.Zero; } finally { context.IsExpandingTemplate = false; context.TemplateOwner = null; context.TemplateBindingSource = null; } // XamlParser needs to ref its return value otherwise we can end up returning a an object to native // code with a refcount of '1' and it could then get GC'ed before we use it. Mono.NativeMethods.event_object_ref (dob.NativeHandle); return dob.NativeHandle; }