Example #1
0
        void UpdateInheritedBindingContexts()
        {
            object bindingContext           = BindingContext;
            RowDefinitionCollection rowDefs = RowDefinitions;

            if (rowDefs != null)
            {
                for (var i = 0; i < rowDefs.Count; i++)
                {
                    RowDefinition rowdef = rowDefs[i];
                    SetInheritedBindingContext(rowdef, bindingContext);
                }
            }

            ColumnDefinitionCollection colDefs = ColumnDefinitions;

            if (colDefs != null)
            {
                for (var i = 0; i < colDefs.Count; i++)
                {
                    ColumnDefinition coldef = colDefs[i];
                    SetInheritedBindingContext(coldef, bindingContext);
                }
            }
        }
        public override object ConvertFromInvariantString(string value)
        {
            if (value != null)
            {
                var lengths   = value.Split(',');
                var coldefs   = new ColumnDefinitionCollection();
                var converter = new GridLengthTypeConverter();
                foreach (var length in lengths)
                {
                    coldefs.Add(new ColumnDefinition {
                        Width = (GridLength)converter.ConvertFromInvariantString(length)
                    });
                }
                return(coldefs);
            }

            throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", value, typeof(ColumnDefinitionCollection)));
        }
Example #3
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var strValue = value?.ToString();

            if (strValue != null)
            {
                var lengths   = strValue.Split(',');
                var coldefs   = new ColumnDefinitionCollection();
                var converter = new GridLengthTypeConverter();
                foreach (var length in lengths)
                {
                    coldefs.Add(new ColumnDefinition {
                        Width = (GridLength)converter.ConvertFromInvariantString(length)
                    });
                }
                return(coldefs);
            }

            throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", strValue, typeof(ColumnDefinitionCollection)));
        }