Exemple #1
0
        protected virtual void addEventHandler(
            Type typeOfControl,
            object control,
            ViewFactory factory,
            BuildContext context,
            PropertyMap pm)
        {
            var name = pm.Name;
            var eventHandlerName = (string)getAttributeValue(context.CurrentNode, typeof(string), name);

            if (string.IsNullOrEmpty(eventHandlerName) == false)
            {
                var ei = getEvent(typeOfControl, name);
                var mi = getEventHandler(context.TypeOfView, eventHandlerName);

                if (ei != null && mi != null)
                {
                    ei.AddEventHandler(control, Delegate.CreateDelegate(ei.EventHandlerType, context.View, mi));
                }
            }
        }
Exemple #2
0
        protected virtual void setControlProperty(
            Type typeOfControl,
            object control,
            ViewFactory factory,
            BuildContext context,
            PropertyMap pm)
        {
            var name = pm.Name;

            PropertyInfo property = getProperty(typeOfControl, name);

            if (property == null || property.CanWrite == false) return;

            object value = getAttributeValue(context.CurrentNode, property.PropertyType, name);

            if (value != null) property.SetValue(control, value, null);
        }
Exemple #3
0
        protected virtual bool tryParseComplexValue(
            Type typeOfControl,
            object control,
            ViewFactory factory,
            BuildContext context,
            PropertyMap pm)
        {
            var name = pm.Name;

            var binding = ComplexParser.GetValue(
                getAttributeValue(context.CurrentNode, typeof(string), name),
                "Binding",
                "Path");

            if (binding != null)
            {
                object source = null;
                PropertyInfo sourceProperty = null;

                // будет работать только если контрол, на который биндимся уже создали (пока что и так хватит)
                if (binding.ContainsKey("SourceControl"))
                {
                    source = factory.GetControl(binding["SourceControl"]);
                    sourceProperty = getProperty(source.GetType(), binding["Path"]);
                }
                else
                {
                    source = context.View;
                    sourceProperty = getProperty(context.TypeOfView, binding["Path"]);
                }

                object target = control;
                PropertyInfo targetProperty = getProperty(typeOfControl, name);

                // тут targetProperty или sourceProperty могут быть фиктивными и потому не надо делать жосткой проверки
                // базовый BindingExpression сам выбросить исключение если надо

                if (source != null &&
                    target != null)
                {
                    EBingingMode mode = EBingingMode.OneTime;

                    if (binding.ContainsKey("Mode")) mode = (EBingingMode)ValueParser.GetValue(typeof(EBingingMode), binding["Mode"]);

                    BindingExpression be = createBindingExpression(
                        mode,
                        source,
                        sourceProperty,
                        target,
                        targetProperty);

                    applyBindingExpression(
                        be,
                        factory,
                        binding);
                }

                return true;
            }

            var resource = ComplexParser.GetValue(
                getAttributeValue(context.CurrentNode, typeof(string), name),
                "Resource",
                "Key");

            if (resource != null)
            {
                var property = getProperty(typeOfControl, name);
                var value = factory.GetLocalString(resource["Key"]);

                if (property != null && property.CanWrite)
                {
                    property.SetValue(control, value, null);
                }

                return true;
            }

            return false;
        }
Exemple #4
0
 protected override bool tryParseComplexValue(Type typeOfControl, object control, ViewFactory factory, BuildContext context, PropertyMap pm)
 {
     return base.tryParseComplexValue(typeOfControl, control, factory, context, pm);
 }