Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/19/10 21:00:30 (13 years ago)
Author:
mkommend
Message:

implemented ContentViews and propagation of view state changes (ticket #982)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/View.cs

    r3403 r3416  
    2121
    2222using System;
     23using System.Linq;
    2324using System.Windows.Forms;
     25using System.Reflection;
     26using System.ComponentModel;
    2427
    2528namespace HeuristicLab.MainForm.WindowsForms {
     
    6568          if (value != readOnly) {
    6669            readOnly = value;
     70            PropertyInfo prop = typeof(IView).GetProperty("ReadOnly");
     71            PropagateStateChanges(this, typeof(IView), prop);
    6772            OnReadOnlyChanged();
    6873          }
     
    135140      }
    136141    }
     142    protected void PropagateStateChanges(Control control, Type type, PropertyInfo propertyInfo) {
     143      if (!type.GetProperties().Contains(propertyInfo))
     144        throw new ArgumentException("The specified type " + type + "implement the property " + propertyInfo.Name + ".");
     145      if (!type.IsAssignableFrom(this.GetType()))
     146        throw new ArgumentException("The specified type " + type + "must be the same or a base class / interface of this object.");
     147      if (!propertyInfo.CanWrite)
     148        throw new ArgumentException("The specified property " + propertyInfo.Name + " must have a setter.");
     149
     150      foreach (Control c in control.Controls) {
     151        Type controlType = c.GetType();
     152        PropertyInfo controlPropertyInfo = controlType.GetProperty(propertyInfo.Name, propertyInfo.PropertyType);
     153        if (type.IsAssignableFrom(controlType) && controlPropertyInfo!= null) {
     154          var thisValue = propertyInfo.GetValue(this, null);
     155          controlPropertyInfo.SetValue(c, thisValue, null);
     156        } else
     157          PropagateStateChanges(c, type, propertyInfo);
     158      }
     159    }
    137160    public event EventHandler Changed;
    138161    protected virtual void OnChanged() {
Note: See TracChangeset for help on using the changeset viewer.