コード例 #1
0
ファイル: control.cpp プロジェクト: snorp/moon
bool
Control::DoApplyTemplateWithError (MoonError *error)
{
    ControlTemplate *t = GetTemplate ();
    if (!t)
        return FrameworkElement::DoApplyTemplateWithError (error);

    // If the template expands to an element which is *not* a UIElement
    // we don't apply the template.
    DependencyObject *root = t->GetVisualTreeWithError (this, error);
    if (root && !root->Is (Type::UIELEMENT)) {
        g_warning ("Control::DoApplyTemplate () Template root was not a UIElement");
        root->unref ();
        root = NULL;
    }

    if (!root)
        return FrameworkElement::DoApplyTemplateWithError (error);

    // No need to ref template_root here as ElementAdded refs it
    // and it is cleared when ElementRemoved is called.
    if (template_root != root && template_root != NULL) {
        template_root->SetParent (NULL, NULL);
        template_root->SetMentor (NULL);
        template_root = NULL;
    }

    template_root = (UIElement *) root;

    ElementAdded (template_root);

    if (IsLoaded ())
        GetDeployment ()->EmitLoadedAsync ();

    root->unref ();

    return true;
}