Example #1
0
        /// <summary>
        /// Adds the specified item to a new row
        /// </summary>
        /// <param name="item">Item to add to a new row</param>
        public void AddRow(DynamicItem item)
        {
            var row = new DynamicRow();

            row.Add(item);
            Rows.Add(row);
        }
Example #2
0
        public override object ConvertFrom(sc.ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var dynamicRow = new DynamicRow();

            dynamicRow.Add(new DynamicControl {
                Control = value as Control
            });
            return(dynamicRow);
        }
Example #3
0
 /// <summary>
 /// Add the specified item to the current row
 /// </summary>
 /// <param name="item">Item to add</param>
 public void Add(DynamicItem item)
 {
     if (CurrentRow != null)
     {
         CurrentRow.Add(item);
     }
     else
     {
         AddRow(item);
     }
 }
Example #4
0
        /// <summary>
        /// Creates the content for this item
        /// </summary>
        /// <param name="layout">Top level layout the item is being created for</param>
        public override Control Create(DynamicLayout layout)
        {
            if (Rows.Count == 0)
            {
                return(null);
            }
            int cols = Rows.Where(r => r != null).Max(r => r.Count);

            var table = Table = new TableLayout(cols, Rows.Count);

            table.IsVisualControl = true;
            var padding = Padding ?? layout.DefaultPadding;

            if (padding != null)
            {
                table.Padding = padding.Value;
            }

            var spacing = Spacing ?? layout.DefaultSpacing;

            if (spacing != null)
            {
                table.Spacing = spacing.Value;
            }

            var scalingRow = new DynamicRow();

            scalingRow.Add(new DynamicControl {
                YScale = true
            });
            for (int cy = 0; cy < Rows.Count; cy++)
            {
                var row = Rows[cy] ?? scalingRow;
                for (int cx = 0; cx < row.Count; cx++)
                {
                    var item = row[cx] ?? new DynamicControl {
                        XScale = true
                    };
                    item.Create(layout, table, cx, cy);
                }
            }
            return(table);
        }
Example #5
0
		public override object ReadJson(Newtonsoft.Json.JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
		{
			object instance;
			JContainer container;
			if (reader.TokenType == JsonToken.Null)
			{
				return null;
			}
			if (reader.TokenType == JsonToken.String)
			{
				if (objectType == typeof(DynamicItem))
					return new DynamicControl { Control =  Convert.ToString(reader.Value) };
				if (objectType == typeof(TableCell))
					return new DynamicRow(new DynamicControl { Control = Convert.ToString(reader.Value) });
			}
			if (reader.TokenType == JsonToken.StartArray)
			{
				container = JArray.Load(reader);
				if (objectType == typeof(DynamicRow))
				{
					var dynamicRow = new DynamicRow();
					instance = dynamicRow;
					serializer.Populate(container.CreateReader(), dynamicRow);
				}
				else if (objectType == typeof(DynamicItem))
				{
					var dynamicTable = new DynamicTable();
					instance = dynamicTable;
					serializer.Populate(container.CreateReader(), dynamicTable.Rows);
				}
				else
					throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Invalid object graph"));
			}
			else
			{
				container = JObject.Load(reader);
				if (container["$type"] == null)
				{
					if (container["Rows"] != null)
						instance = new DynamicTable();
					else if (container["Control"] != null)
						instance = new DynamicControl();
					else
						throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Could not infer the type of object to create"));

					serializer.Populate(container.CreateReader(), instance);
				}
				else
				{
					var type = Type.GetType((string)container["$type"]);
					if (!typeof(DynamicItem).IsAssignableFrom(type))
					{
						var dynamicControl = new DynamicControl();
						dynamicControl.Control = serializer.Deserialize(container.CreateReader()) as Control;
						instance = dynamicControl;
					}
					else
					{
						instance = serializer.Deserialize(container.CreateReader());
					}
				}
			}
			if (objectType == typeof(DynamicRow) && instance.GetType() != typeof(DynamicRow))
			{
				var row = new DynamicRow();
				row.Add(instance as DynamicItem);
				return row;
			}

			return instance;
		}
Example #6
0
		public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
		{
			var dynamicRow = new DynamicRow();
			dynamicRow.Add(new DynamicControl { Control = value as Control });
			return dynamicRow;
		}