Example #1
0
        private void BindProperty(BaseDefinition source, FrameworkElement boundElement, string sourcePropertyName, DependencyProperty property, IValueConverter converter = null)
        {
            Binding binding = new Binding(sourcePropertyName);

            binding.Source = source;
            binding.Mode   = BindingMode.OneWay;
            if (converter != null)
            {
                binding.Converter = converter;
            }
            boundElement.SetBinding(property, binding);
        }
Example #2
0
        public FrameworkElement ExtractAndBind(BaseDefinition model)
        {
            Type             ElementType = TypeDictionary[model.GetType()];
            FrameworkElement UIElement   = ControlFactory.CreateControl(ElementType);

            PropertyInfo[] properties = model.GetType().GetProperties();
            foreach (var property in properties)
            {
                object             value = property.GetValue(model);
                DependencyProperty boundProperty;
                bool propertyFound = propertyFinder.TryGetProperty(property.Name, out boundProperty);
                if (propertyFound)
                {
                    IValueConverter converter;
                    bool            converterExists = propertyFinder.TryGetConverter(boundProperty, out converter);
                    if (converterExists)
                    {
                        value = converter.Convert(value, null, null, null);
                    }
                    UIElement.SetValue(boundProperty, value);
                    BindProperty(model, UIElement, property.Name, boundProperty, converter);
                }
            }
            model.Control = UIElement;

            if (model is ViewGroup)
            {
                ViewGroup vg = model as ViewGroup;
                Panel     p  = UIElement as Panel;
                foreach (var child in vg.Children)
                {
                    p.Children.Add(ExtractAndBind(child));
                }
            }
            return(UIElement);
        }