本文整理汇总了C#中Binding.ReadValue方法的典型用法代码示例。如果您正苦于以下问题:C# Binding.ReadValue方法的具体用法?C# Binding.ReadValue怎么用?C# Binding.ReadValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Binding
的用法示例。
在下文中一共展示了Binding.ReadValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyWriteRules
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: ApplyReadRules
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;
}