本文整理汇总了C#中Control.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# Control.SetBinding方法的具体用法?C# Control.SetBinding怎么用?C# Control.SetBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Control
的用法示例。
在下文中一共展示了Control.SetBinding方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadProperty
private static void LoadProperty(Control control, XmlAttribute attr, PropertyInfo pi, object viewModel)
{
object value = attr.Value;
if (((string)value).StartsWith("{"))
// If we start with the curly brace, then we're going to try and load a markup extension
value = LoadMarkupExtension((string)value, control);
else if (pi.PropertyType.IsEnumOrNullableEnum())
value = Enum.Parse(pi.PropertyType.GetUnderlyingType(), attr.Value, true);
else if (pi.PropertyType != Constants.STRING_TYPE)
{
// String values don't need to be converted
var tc = TypeConverters[Constants.STRING_TYPE].FirstOrDefault(t => t.CanConvert(Constants.STRING_TYPE, pi.PropertyType));
if (tc != null)
value = tc.ConvertTo(value);
else
{
// This is probably just converting between primitive types (or we're missing a type converter)
// We need to handle nullable types as well
var t = pi.PropertyType;
t = Nullable.GetUnderlyingType(t) ?? t;
// Coalesce to set the safe value using the default of t or the safe type.
value = value == null ? t.Default() : Convert.ChangeType(value, t);
}
}
if (value is Binding)
control.SetBinding(control.GetDependencyProperty(attr.LocalName), value as Binding);
else
pi.SetValue(control, value, null);
}