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;
}