Beispiel #1
0
void
Popup::OnPropertyChanged (PropertyChangedEventArgs *args, MoonError *error)
{
	if (args->GetProperty ()->GetOwnerType() != Type::POPUP) {
		FrameworkElement::OnPropertyChanged (args, error);
		return;
	}
	
	if (args->GetId () == Popup::IsOpenProperty) {
		// we intentionally don't track whether we've added a tick
		// call (to make sure we only add it once) for this event
		// because multiple IsOpen changes cause multiple async events
		// in SL.
		if (args->GetNewValue () && args->GetNewValue ()->AsBool ()) {
			Show (GetChild ());
			
			EmitAsync (Popup::OpenedEvent);
		}
		else {
			Hide (GetChild ());
			
			EmitAsync (Popup::ClosedEvent);
		}
	} else if (args->GetId () == Popup::ChildProperty) {
		if (args->GetOldValue () && !args->GetOldValue ()->GetIsNull ()) {
			FrameworkElement *el = args->GetOldValue ()->AsFrameworkElement ();
			if (GetIsOpen ())
				Hide (el);

			el->SetLogicalParent (NULL, error);
			if (error->number)
				return;
		}
		if (args->GetNewValue () && !args->GetNewValue ()->GetIsNull ()) {
			FrameworkElement *el = args->GetNewValue ()->AsFrameworkElement ();
			el->SetLogicalParent (this, error);
			if (error->number) 
				return;
			
			if (GetIsOpen ())
				Show (el);
		}
	} else if (args->GetId () == Popup::HorizontalOffsetProperty
		   || args->GetId () == Popup::VerticalOffsetProperty) {
		UIElement * child = GetChild ();
		if (child)
			child->UpdateTransform ();
	}
	NotifyListenersOfPropertyChange (args, error);
}
Beispiel #2
0
void
Control::OnPropertyChanged (PropertyChangedEventArgs *args, MoonError *error)
{
    if (args->GetProperty ()->GetOwnerType() != Type::CONTROL) {
        FrameworkElement::OnPropertyChanged (args, error);
        return;
    }

    if (args->GetId () == Control::TemplateProperty) {
        if (GetSubtreeObject ())
            ElementRemoved ((UIElement *) GetSubtreeObject ());
        InvalidateMeasure ();
    }
    else if (args->GetId () == Control::PaddingProperty
             || args->GetId () == Control::BorderThicknessProperty) {
        InvalidateMeasure ();
    } else if (args->GetId () == Control::IsEnabledProperty) {
        if (!args->GetNewValue ()->AsBool ()) {
            Surface *surface = Deployment::GetCurrent ()->GetSurface ();
            if (surface && surface->GetFocusedElement () == this) {
                // Ensure this element loses focus, then try to focus the next suitable element
                surface->FocusElement (NULL);
                TabNavigationWalker::Focus (this, true);
            }
            ReleaseMouseCapture ();
        }
        PropertyChangedEventArgs *pargs = new PropertyChangedEventArgs (args->GetProperty(),
                args->GetId (),
                args->GetOldValue(),
                args->GetNewValue());
        EmitAsync (IsEnabledChangedEvent, pargs);
    } else if (args->GetId () == Control::HorizontalContentAlignmentProperty
               || args->GetId () == Control::VerticalContentAlignmentProperty) {
        InvalidateArrange ();
    }
    NotifyListenersOfPropertyChange (args, error);
}