Esempio n. 1
0
        public static IVisualContainer GetStackPanel <TViewModel, TProperty>(Orientations orientation,
                                                                             String propertyName)
        {
            var prop = typeof(TViewModel).GetProperty(propertyName);

            if (prop == null)
            {
                throw new InvalidOperationException();
            }

            var isCollection = typeof(IEnumerable <TProperty>).IsAssignableFrom(prop.PropertyType);

            if (isCollection)
            {
                var binding = new DeferredPropertyBinding <IEnumerable <TProperty> >(prop);
                return(new StackPanel <IEnumerable <TProperty> >
                {
                    Binding = binding, Orientation = orientation
                });
            }
            else
            {
                var binding = new DeferredPropertyBinding <TProperty>(prop);
                return(new StackPanel <TProperty>
                {
                    Binding = binding, Orientation = orientation
                });
            }
        }
Esempio n. 2
0
        public Boolean TryGetValue(ITextNode node,
                                   String attributeName,
                                   String attributeText,
                                   out Object value)
        {
            if (attributeName != "Binding" ||
                node.Value == null ||
                node.Type == null)
            {
                goto fail;
            }

            var valType     = node.Value.GetType();
            var bindingProp = valType.GetProperty("Binding");

            if (bindingProp == null)
            {
                goto fail;
            }

            var gargs = bindingProp.PropertyType.GenericTypeArguments;

            if (gargs.Length == 0)
            {
                var propBinding = _propertyProvider.GetPropertyAccessor(node.Type, "Binding");

                value = new DeferredPropertyBinding(attributeText, "Binding", propBinding, null);
                return(true);
            }

            if (gargs.Length == 1)
            {
                var genericDeferred = typeof(DeferredPropertyNameBinding <>).MakeGenericType(gargs[0]);
                var ctor            = genericDeferred.GetConstructor(new[] { typeof(String) });
                if (ctor == null)
                {
                    goto fail;
                }

                value = ctor.Invoke(new Object[] { attributeText });
                return(true);
            }

fail:
            value = default !;
Esempio n. 3
0
        public IView <CompanyViewModel> GetCompanyView(IStyleContext styleContext)
        {
            var companyVm  = typeof(CompanyViewModel);
            var employeeVm = typeof(EmployeeViewModel);

            var companyView = new View <CompanyViewModel>(styleContext);

            var employeesBinding = new DeferredPropertyBinding <IEnumerable <EmployeeViewModel> >
                                       (companyVm, nameof(CompanyViewModel.Employees));
            var employeesView = new RepeaterPanel <EmployeeViewModel>(employeesBinding);

            var employeeView = new StackPanel <EmployeeViewModel>
            {
                Orientation = Orientations.Horizontal
            };

            var lblFirst = new Label(new DeferredPropertyBinding <string>(employeeVm,
                                                                          nameof(EmployeeViewModel.FirstName)));

            var lblLast = new Label(new DeferredPropertyBinding <string>(employeeVm,
                                                                         nameof(EmployeeViewModel.LastName)));

            employeeView.AddChild(lblFirst);
            employeeView.AddChild(lblLast);

            var labelStyle0 = new StyleForLabel(lblFirst, 12, FontStyle.Regular, Color.White);

            styleContext.RegisterStyle(labelStyle0);

            var labelStyle = new StyleForLabel(lblLast, 18, FontStyle.Bold, Color.Orange);

            styleContext.RegisterStyle(labelStyle);

            employeesView.Content = employeeView;
            companyView.Content   = employeesView;

            return(companyView);
        }