示例#1
0
        protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
        {
            base.OnRenderSizeChanged(sizeInfo);

            var size = new Size(ActualWidth, ActualHeight);

            _propertyService.SetValue(ControlSizeProperty, size);
        }
示例#2
0
        private System.Windows.TriggerAction CreateTriggerAction(StyleSheet styleSheet, DependencyObject styleResourceReferenceHolder, TriggerAction action)
        {
            string actionTypeName = null;
            Type   actionType     = null;

            System.Windows.TriggerAction nativeTriggerAction = null;

            actionTypeName      = typeNameResolver.ResolveFullTypeName(styleSheet.Namespaces, action.Action);
            actionType          = Type.GetType(actionTypeName);
            nativeTriggerAction = (System.Windows.TriggerAction)Activator.CreateInstance(actionType);

            foreach (var parameter in action.Parameters)
            {
                string parameterName            = null;
                object value                    = null;
                string parameterValueExpression = null;
                DependencyPropertyInfo <DependencyProperty> propertyInfo;
                Type type = null;

                parameterName            = parameter.Property;
                parameterValueExpression = parameter.Value.Trim();
                type = typeNameResolver.GetClrPropertyType(styleSheet.Namespaces, nativeTriggerAction, parameterName);
                if (typeNameResolver.IsMarkupExtension(parameterValueExpression))
                {
                    value = typeNameResolver.GetMarkupExtensionValue(styleResourceReferenceHolder, parameterValueExpression, styleSheet.Namespaces, false);
                }
                else if ((propertyInfo = typeNameResolver.GetDependencyPropertyInfo(styleSheet.Namespaces, actionType, parameterName)) != null)
                {
                    value = typeNameResolver.GetPropertyValue(propertyInfo.DeclaringType, styleResourceReferenceHolder, propertyInfo.Name, parameterValueExpression, propertyInfo.Property, styleSheet.Namespaces);

                    if (value is DynamicResourceExtension)
                    {
                        var dyn = value as DynamicResourceExtension;
                        serviceProvider = serviceProvider ?? (serviceProvider = (IServiceProvider)typeof(Application).GetProperty("ServiceProvider", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(Application.Current));
                        value           = dyn.ProvideValue(serviceProvider);
                    }
                    else if (value is StaticResourceExtension)
                    {
                        var dyn = value as StaticResourceExtension;
                        serviceProvider = serviceProvider ?? (serviceProvider = (IServiceProvider)typeof(Application).GetProperty("ServiceProvider", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(Application.Current));
                        value           = dyn.ProvideValue(serviceProvider);
                    }
                }
                else
                {
                    value = parameterValueExpression;
                }

                if (value is string valueString)
                {
                    value = TypeDescriptor.GetConverter(type)?.ConvertFromInvariantString(valueString) ?? value;
                }

                if (value == null)
                {
                }

                dependencyService.SetValue(nativeTriggerAction, parameterName, value);
            }

            return(nativeTriggerAction);
        }