Пример #1
0
    private void ApplyWriteRules(
      Control ctl, Binding binding,
      bool canWrite)
    {
      if (ctl is Label) return;

      // enable/disable writing of the value
      PropertyInfo propertyInfo =
        ctl.GetType().GetProperty("ReadOnly",
        BindingFlags.FlattenHierarchy |
        BindingFlags.Instance |
        BindingFlags.Public);
      if (propertyInfo != null)
      {
        bool couldWrite =
          (!(bool)propertyInfo.GetValue(
          ctl, new object[] { }));
        propertyInfo.SetValue(
          ctl, !canWrite, new object[] { });
        if ((!couldWrite) && (canWrite))
          binding.ReadValue();
      }
      else
      {
        bool couldWrite = ctl.Enabled;
        ctl.Enabled = canWrite;
        if ((!couldWrite) && (canWrite))
          binding.ReadValue();
      }
    }
Пример #2
0
		public void ReadValueTest ()
		{
			Control c = new Control ();
			c.BindingContext = new BindingContext ();
			c.CreateControl ();

			ChildMockItem item = new ChildMockItem ();
			item.ObjectValue = "A";
			Binding binding = new Binding ("Tag", item, "ObjectValue");
			binding.ControlUpdateMode = ControlUpdateMode.Never;

			c.DataBindings.Add (binding);
			Assert.AreEqual (null, c.Tag, "#A1");

			item.ObjectValue = "B";
			Assert.AreEqual (null, c.Tag, "#B1");

			binding.ReadValue ();
			Assert.AreEqual ("B", c.Tag, "#C1");

			item.ObjectValue = "C";
			binding.ReadValue ();
			Assert.AreEqual ("C", c.Tag, "#D1");
			
			c.Dispose();
		}
Пример #3
0
    private void ApplyReadRules(
      Control ctl, Binding binding,
      bool canRead)
    {
      var status = GetControlStatus(ctl);

      // enable/disable reading of the value
      if (canRead)
      {
        ctl.Enabled = true;
        // if !CanRead remove format event and refresh value 
        if (!status.CanRead)
        {
          binding.Format -= ReturnEmpty;
          binding.ReadValue();
        }
      }
      else
      {
        ctl.Enabled = false;
        if (status.CanRead)
        {
          binding.Format += ReturnEmpty;
        }

        // clear the value displayed by the control
        var propertyInfo = ctl.GetType().GetProperty(binding.PropertyName,
          BindingFlags.FlattenHierarchy |
          BindingFlags.Instance |
          BindingFlags.Public);
        if (propertyInfo != null)
        {
          propertyInfo.SetValue(ctl,
            GetEmptyValue(
            Utilities.GetPropertyType(
              propertyInfo.PropertyType)),
            new object[] { });
        }
      }

      // store new status
      status.CanRead = canRead;
    }