DependencyObject.ClearValue 方法
2013/3/11
清除依赖项属性的本地值。
程序集: System.Windows(位于 System.Windows.dll 中)
参数
- dp
- 类型: System.Windows.DependencyProperty
要为其清除值的属性的 DependencyProperty 标识符。
下面的示例使用 ReadLocalValue 检查现有本地值。如果有本地值,按照不返回 UnsetValue 的指示,会通过调用 ClearValue 移除现有本地值。
public static bool ClearSetProperty(DependencyObject targetObject, DependencyProperty targetDP) { if (targetObject == null || targetDP == null) { throw new ArgumentNullException(); } object localValue = targetObject.ReadLocalValue(targetDP); if (localValue == DependencyProperty.UnsetValue) { return false; } else { targetObject.ClearValue(targetDP); return true; } }