Skip to content

Commit

Permalink
GridViewColumn Header... made bindable against dataContext fo the grid
Browse files Browse the repository at this point in the history
  • Loading branch information
exyi committed Jul 9, 2016
1 parent a6846ee commit 8da15e0
Show file tree
Hide file tree
Showing 16 changed files with 838 additions and 802 deletions.
13 changes: 0 additions & 13 deletions src/DotVVM.Framework/Binding/DataContextChangeAttribute.cs
Expand Up @@ -17,18 +17,5 @@ public abstract class DataContextChangeAttribute : Attribute
public abstract int Order { get; }

public abstract ITypeDescriptor GetChildDataContextType(ITypeDescriptor dataContext, IDataContextStack controlContextStack, IAbstractControl control, IPropertyDescriptor property = null);

public static ITypeDescriptor GetDataContextExpression(IDataContextStack dataContextStack, ResolvedControl control, DotvvmProperty property = null)
{
var attributes = property == null ? control.Metadata.Type.GetCustomAttributes<DataContextChangeAttribute>().ToArray() : property.PropertyInfo?.GetCustomAttributes<DataContextChangeAttribute>().ToArray();
if (attributes == null || attributes.Length == 0) return null;

var type = dataContextStack.DataContextType;
foreach (var attribute in attributes.OrderBy(a => a.Order))
{
type = attribute.GetChildDataContextType(type, dataContextStack, control, property);
}
return type;
}
}
}
7 changes: 6 additions & 1 deletion src/DotVVM.Framework/Binding/DotvvmProperty.cs
Expand Up @@ -93,6 +93,9 @@ public string FullName
[JsonIgnore]
public DataContextChangeAttribute[] DataContextChangeAttributes { get; private set; }

[JsonIgnore]
public DataContextStackManipulationAttribute DataContextManipulationAttribute { get; private set; }

/// <summary>
/// Prevents a default instance of the <see cref="DotvvmProperty"/> class from being created.
/// </summary>
Expand Down Expand Up @@ -203,7 +206,9 @@ public virtual void SetValue(DotvvmBindableObject control, object value)
property.IsValueInherited = isValueInherited;
property.PropertyInfo = propertyInfo;
property.DataContextChangeAttributes = (propertyInfo != null ? propertyInfo.GetCustomAttributes<DataContextChangeAttribute>(true) : field.GetCustomAttributes<DataContextChangeAttribute>()).ToArray();
property.MarkupOptions = markupOptions;
property.DataContextManipulationAttribute = propertyInfo != null ? propertyInfo.GetCustomAttribute<DataContextStackManipulationAttribute>(true) : field.GetCustomAttribute<DataContextStackManipulationAttribute>();
if (property.DataContextManipulationAttribute != null && property.DataContextChangeAttributes.Any()) throw new ArgumentException($"{nameof(DataContextChangeAttributes)} and {nameof(DataContextManipulationAttribute)} can not be set both at property '{fullName}'.");
property.MarkupOptions = markupOptions;
property.IsBindingProperty = typeof(IBinding).IsAssignableFrom(property.PropertyType);
return property;
});
Expand Down
Expand Up @@ -29,16 +29,22 @@ public ControlResolverMetadata(ControlType controlType) : base(controlType)
this.controlType = controlType;

DataContextChangeAttributes = Type.GetCustomAttributes<DataContextChangeAttribute>(true).ToArray();
DataContextManipulationAttribute = Type.GetCustomAttribute<DataContextStackManipulationAttribute>(true);
if (DataContextManipulationAttribute != null && DataContextChangeAttributes.Any())
throw new Exception($"{nameof(DataContextChangeAttributes)} and {nameof(DataContextManipulationAttribute)} can not be set at the same time at control '{controlType.Type.FullName}'.");
}

public ControlResolverMetadata(Type type) : base(new ControlType(type))
{
}

[JsonIgnore]
public override DataContextChangeAttribute[] DataContextChangeAttributes { get; }
public override sealed DataContextChangeAttribute[] DataContextChangeAttributes { get; }
[JsonIgnore]
public override sealed DataContextStackManipulationAttribute DataContextManipulationAttribute { get; }

protected override void LoadProperties(Dictionary<string, IPropertyDescriptor> result)

protected override void LoadProperties(Dictionary<string, IPropertyDescriptor> result)
{
foreach (var property in DotvvmProperty.ResolveProperties(controlType.Type).Concat(DotvvmProperty.GetVirtualProperties(controlType.Type)))
{
Expand Down
Expand Up @@ -62,9 +62,12 @@ public IPropertyDescriptor DefaultContentProperty
public IEnumerable<IPropertyDescriptor> AllProperties => Properties.Values;

[JsonIgnore]
public abstract DataContextChangeAttribute[] DataContextChangeAttributes { get; }
public abstract DataContextChangeAttribute[] DataContextChangeAttributes { get; }
[JsonIgnore]
public abstract DataContextStackManipulationAttribute DataContextManipulationAttribute { get; }

public ControlResolverMetadataBase(IControlType controlType)

public ControlResolverMetadataBase(IControlType controlType)
{
this.controlType = controlType;
this.attribute = controlType?.Type?.GetControlMarkupOptionsAttribute();
Expand Down

0 comments on commit 8da15e0

Please sign in to comment.