Example #1
0
        private void ApplyCSSChanges(Matrix matrix)
        {
            CSSEquivalent cssEquivalent = MatrixProperty.GetTypeMetaData(typeof(MatrixTransform)).GetCSSEquivalent(this);

            if (cssEquivalent != null)
            {
                object domElement = cssEquivalent.DomElement;
                INTERNAL_HtmlDomManager.SetDomElementStyleProperty(
                    cssEquivalent.DomElement,
                    cssEquivalent.Name,
                    cssEquivalent.Value(this, matrix));
            }
        }
Example #2
0
        private void ApplyCSSChanges(Matrix m)
        {
            var target = this.INTERNAL_parent;

            if (target != null)
            {
                INTERNAL_HtmlDomManager.SetDomElementStyleProperty(
                    target.INTERNAL_OuterDomElement,
                    new List <string>(1)
                {
                    "transform"
                },
                    string.Format(CultureInfo.InvariantCulture,
                                  "matrix({0}, {1}, {2}, {3}, {4}, {5})",
                                  m.M11, m.M12, m.M21, m.M22, m.OffsetX, m.OffsetY));
            }
        }
Example #3
0
        public override object CreateDomElement(object parentRef, out object domElementWhereToPlaceChildren)
        {
            if (_useNativeComboBox)
            {
                var select = INTERNAL_HtmlDomManager.CreateDomElementAndAppendIt("select", parentRef, this);
                domElementWhereToPlaceChildren = select;
                _nativeComboBoxDomElement      = select;

                INTERNAL_EventsHelper.AttachToDomEvents("change", select, (Action <object>)(e =>
                {
                    DomSelectionChanged(select);
                }));

                INTERNAL_HtmlDomManager.SetDomElementStyleProperty(select, new List <string>()
                {
                    "fontSize"
                }, "inherit");

                // Add an empty element that will make it easier to have nothing selected when items are added to the ComboBox: // See: http://stackoverflow.com/questions/8605516/default-select-option-as-blank
                var emptyOption = INTERNAL_HtmlDomManager.AddOptionToNativeComboBox(_nativeComboBoxDomElement, "");
                CSHTML5.Interop.ExecuteJavaScriptAsync("$0.disabled = true", emptyOption);
                CSHTML5.Interop.ExecuteJavaScriptAsync("$0.selected = true", emptyOption);
                CSHTML5.Interop.ExecuteJavaScriptAsync("$0.style.display = 'hidden'", emptyOption);

                // Set the mark saying that the pointer events must be "absorbed" by the ComboBox:
                INTERNAL_HtmlDomManager.SetDomElementProperty(select, "data-absorb-events", true);

                return(select);
            }
            else
            {
#if !BRIDGE
                return(base.CreateDomElement(parentRef, out domElementWhereToPlaceChildren));
#else
                return(CreateDomElement_WorkaroundBridgeInheritanceBug(parentRef, out domElementWhereToPlaceChildren));
#endif
            }
        }
Example #4
0
        public override object CreateDomElement(object parentRef, out object domElementWhereToPlaceChildren)
        {
            var select = INTERNAL_HtmlDomManager.CreateDomElementAndAppendIt("select", parentRef, this);

            domElementWhereToPlaceChildren = select;
            this._nativeComboBoxDomElement = select;

            INTERNAL_HtmlDomManager.SetDomElementStyleProperty(select, new List <string>()
            {
                "fontSize"
            }, "inherit");

            // Set the mark saying that the pointer events must be "absorbed" by the ComboBox:
            INTERNAL_HtmlDomManager.SetDomElementProperty(select, "data-absorb-events", true);

            // Fill the ComboBox and synchronize selection properties
            this.Refresh();

            // Listen to native selection change event
            this.SubscribeToHtmlChangeEvent();

            return(select);
        }
        private static void ApplyPropertyChanged(DependencyObject sender, CSSEquivalent cssEquivalent, object oldValue, object newValue)
        {
            //if (cssEquivalent.ApplyWhenControlHasTemplate) //Note: this is to handle the case of a Control with a ControlTemplate (some properties must not be applied on the control itself)

            if (cssEquivalent.Name != null && cssEquivalent.Name.Count > 0 || cssEquivalent.CallbackMethod != null)
            {
                UIElement uiElement = cssEquivalent.UIElement ?? (sender as UIElement); // If no UIElement is specified, we assume that the property is intended to be applied to the instance on which the PropertyChanged has occurred.

                bool hasTemplate = (uiElement is Control) && ((Control)uiElement).HasTemplate;

                if (!hasTemplate || cssEquivalent.ApplyAlsoWhenThereIsAControlTemplate)
                {
                    if (cssEquivalent.CallbackMethod != null)// && cssEquivalent.UIElement != null) //Note: I don't see when the commented part of this test could be false so I'm commenting it and we'll put it back if needed.
                    {
                        //PropertyInfo propertyInfo = uiElement.GetType().GetProperty(cssEquivalent.DependencyProperty.Name);

                        //Type propertyType = propertyInfo.PropertyType;
                        //var castedValue = DynamicCast(newValue, propertyType); //Note: we put this line here because the Xaml could use a Color gotten from a StaticResource (which was therefore not converted to a SolidColorbrush by the compiler in the .g.cs file) and led to a wrong type set in a property (Color value in a property of type Brush).
                        //uiElement.SetVisualStateValue(cssEquivalent.DependencyProperty, castedValue);

                        cssEquivalent.CallbackMethod(cssEquivalent.UIElement, new DependencyPropertyChangedEventArgs(oldValue, newValue, cssEquivalent.DependencyProperty));
                    }
                    else
                    {
                        if (cssEquivalent.DomElement == null && uiElement != null)
                        {
                            cssEquivalent.DomElement = uiElement.INTERNAL_OuterDomElement; // Default value
                        }
                        if (cssEquivalent.DomElement != null)
                        {
                            if (newValue is ICanConvertToCSSValue)
                            {
                                cssEquivalent.Value = (finalInstance, value) => { return(((ICanConvertToCSSValue)value).ConvertToCSSValue()); };
                            }
                            if (newValue is ICanConvertToCSSValues)
                            {
                                cssEquivalent.Values = (finalInstance, value) => { return(((ICanConvertToCSSValues)value).ConvertToCSSValues(sender)); };
                            }
                            if (cssEquivalent.Value == null)
                            {
                                cssEquivalent.Value = (finalInstance, value) => { return(value ?? ""); }; // Default value
                            }
                            if (cssEquivalent.Values != null)
                            {
                                List <object> cssValues = cssEquivalent.Values(sender, newValue);

                                if (cssEquivalent.OnlyUseVelocity)
                                {
                                    foreach (object cssValue in cssValues)
                                    {
                                        INTERNAL_HtmlDomManager.SetDomElementStylePropertyUsingVelocity(cssEquivalent.DomElement, cssEquivalent.Name, cssValue);
                                    }
                                }
                                else
                                {
                                    foreach (object cssValue in cssValues)
                                    {
                                        INTERNAL_HtmlDomManager.SetDomElementStyleProperty(cssEquivalent.DomElement, cssEquivalent.Name, cssValue);
                                    }
                                }
                            }
                            else if (cssEquivalent.Value != null) //I guess we cannot have both defined
                            {
                                object cssValue = cssEquivalent.Value(sender, newValue);

                                if (!(cssValue is Dictionary <string, object>))
                                {
                                    if (cssEquivalent.OnlyUseVelocity)
                                    {
                                        INTERNAL_HtmlDomManager.SetDomElementStylePropertyUsingVelocity(cssEquivalent.DomElement, cssEquivalent.Name, cssValue);
                                    }
                                    else
                                    {
                                        INTERNAL_HtmlDomManager.SetDomElementStyleProperty(cssEquivalent.DomElement, cssEquivalent.Name, cssValue);
                                    }
                                }
                                else
                                {
                                    //Note: currently, only Color needs to set multiple values when using Velocity (which is why cssValue is a Dictionary), which is why it has a special treatment.
                                    //todo: if more types arrive here, find a way to have a more generic way of handling it ?
                                    if (newValue is Color)
                                    {
                                        Color newColor = (Color)newValue;
                                        if (cssEquivalent.OnlyUseVelocity)
                                        {
                                            INTERNAL_HtmlDomManager.SetDomElementStylePropertyUsingVelocity(cssEquivalent.DomElement, cssEquivalent.Name, newColor.INTERNAL_ToHtmlStringForVelocity());
                                        }
                                        else
                                        {
                                            INTERNAL_HtmlDomManager.SetDomElementStyleProperty(cssEquivalent.DomElement, cssEquivalent.Name, newColor.INTERNAL_ToHtmlString(1d));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                throw new InvalidOperationException("Please set the Name property of the CSSEquivalent class.");
            }
        }