本文整理汇总了C#中System.Windows.DependencyProperty.GetDefaultValue方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyProperty.GetDefaultValue方法的具体用法?C# DependencyProperty.GetDefaultValue怎么用?C# DependencyProperty.GetDefaultValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.DependencyProperty
的用法示例。
在下文中一共展示了DependencyProperty.GetDefaultValue方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetValueImpl
internal void SetValueImpl (DependencyProperty dp, object value)
{
bool updateTwoWay = false;
bool addingExpression = false;
Expression existing;
Expression expression = value as Expression;
BindingExpressionBase bindingExpression = expression as BindingExpressionBase;
if (bindingExpression != null) {
string path = bindingExpression.Binding.Path.Path;
if ((string.IsNullOrEmpty (path) || path == ".") &&
bindingExpression.Binding.Mode == BindingMode.TwoWay)
throw new ArgumentException ("TwoWay bindings require a non-empty Path");
bindingExpression.Binding.Seal ();
}
expressions.TryGetValue (dp, out existing);
if (expression != null) {
if (existing != expression) {
if (expression.Attached)
throw new ArgumentException ("Cannot attach the same Expression to multiple FrameworkElements");
if (existing != null)
RemoveExpression (dp);
expressions.Add (dp, expression);
expression.OnAttached (this);
}
addingExpression = true;
value = expression.GetValue (dp);
} else if (existing != null) {
if (existing is BindingExpressionBase) {
BindingExpressionBase beb = (BindingExpressionBase)existing;
if (beb.Binding.Mode == BindingMode.TwoWay) {
updateTwoWay = !beb.Updating && !(dp is CustomDependencyProperty);
} else if (!beb.Updating || beb.Binding.Mode == BindingMode.OneTime) {
RemoveExpression (dp);
}
}
else if (!existing.Updating) {
RemoveExpression (dp);
}
}
try {
NativeDependencyObjectHelper.SetValue (this, dp, value);
if (updateTwoWay)
((BindingExpressionBase)existing).TryUpdateSourceObject (value);
} catch {
if (!addingExpression)
throw;
else {
NativeDependencyObjectHelper.SetValue (this, dp, dp.GetDefaultValue (this));
if (updateTwoWay)
((BindingExpressionBase)existing).TryUpdateSourceObject (value);
}
}
}
示例2: InvokeChangedCallback
static void InvokeChangedCallback(DependencyObject obj, DependencyProperty property, PropertyChangedCallback callback,
object old_obj, object new_obj)
{
if (old_obj == null && property.property_type.IsValueType && !property.IsNullable) {
old_obj = property.GetDefaultValue (obj);
Console.WriteLine ("WARNING: Got a null value for {0}.{1} which is a value type", property.DeclaringType.Name, property.Name);
}
if (Helper.AreEqual (property.PropertyType, old_obj, new_obj))
return;
var args = new DependencyPropertyChangedEventArgs (old_obj, new_obj, property);
// note: since callbacks might throw exceptions but we cannot catch them
callback (obj, args);
}
示例3: GetValue
/// <summary>
/// Called to evaluate the Expression value
/// </summary>
/// <param name="d">DependencyObject being queried</param>
/// <param name="dp">Property being queried</param>
/// <returns>Computed value. Default (of the target) if unavailable.</returns>
internal override object GetValue(DependencyObject d, DependencyProperty dp)
{
return dp.GetDefaultValue(d.DependencyObjectType);
}
示例4: ConvertToType
object ConvertToType (DependencyProperty dp, object value)
{
try {
if (!PropertyPathWalker.IsPathBroken && Binding.Converter != null) {
value = Binding.Converter.Convert (
value,
Property.PropertyType,
Binding.ConverterParameter,
GetConverterCulture ()
);
}
if (value == DependencyProperty.UnsetValue || PropertyPathWalker.IsPathBroken) {
value = Binding.FallbackValue ?? dp.GetDefaultValue (Target);
}
else if (value == null) {
value = Binding.TargetNullValue;
if (value == null && IsBoundToAnyDataContext && string.IsNullOrEmpty (Binding.Path.Path))
value = dp.GetDefaultValue (Target);
} else {
string format = Binding.StringFormat;
if (!string.IsNullOrEmpty (format)) {
if (!format.Contains ("{0"))
format = "{0:" + format + "}";
value = string.Format (GetConverterCulture (), format, value);
}
}
if (value != null) {
value = ConvertFromSourceToTarget (value);
}
} catch (Exception ex) {
return MoonlightTypeConverter.ConvertObject (dp, Binding.FallbackValue, Target.GetType (), true);
}
return value;
}
示例5: GetValue
internal override object GetValue (DependencyProperty dp)
{
if (cached)
return cachedValue;
cached = true;
if (PropertyPathWalker.IsPathBroken) {
cachedValue = null;
}
else {
cachedValue = PropertyPathWalker.Value;
}
try {
cachedValue = ConvertToType (dp, cachedValue);
} catch {
cachedValue = dp.GetDefaultValue (Target);
}
return cachedValue;
}
示例6: GetValue
internal override object GetValue (DependencyProperty dp)
{
if (cached)
return cachedValue;
cached = true;
if (DataSource == null) {
cachedValue = dp.GetDefaultValue (Target);
return cachedValue;
}
else if (PropertyPathWalker.IsPathBroken) {
// If it the path is broken, don't call the converter unless we use the fallback.
// FIXME: Add an explicit test on this.
if (Binding.FallbackValue == null) {
cachedValue = dp.GetDefaultValue (Target);
return cachedValue;
}
cachedValue = Binding.FallbackValue;
}
else {
cachedValue = PropertyPathWalker.Value;
}
try {
cachedValue = ConvertToType (dp, cachedValue);
} catch {
cachedValue = dp.GetDefaultValue (Target);
}
return cachedValue;
}
示例7: GetConvertedFallbackOrDefaultValue
private object GetConvertedFallbackOrDefaultValue(DependencyObject d, DependencyProperty dp)
{
if (this.binding.FallbackValue != null)
{
return this.ConvertedFallbackValue;
}
return dp.GetDefaultValue(d);
}
示例8: GetValue
internal override object GetValue(DependencyObject d, DependencyProperty dp)
{
if (this.listener != null && this.listener.FullPathExists)
{
return this.ConvertToTarget(this.listener.LeafValue);
}
if (this.listener == null || !this.binding.Path.IsPathToSource)
{
return this.GetConvertedFallbackOrDefaultValue(d, dp);
}
if (this.binding.TargetNullValue != null)
{
return this.ConvertToTarget(null);
}
return dp.GetDefaultValue(d);
}