|
|
|
@ -331,6 +331,32 @@ namespace Perspex |
|
|
|
return this.values.ContainsKey(property); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Sets a <see cref="PerspexProperty"/> value.
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="T">The type of the property.</typeparam>
|
|
|
|
/// <param name="property">The property.</param>
|
|
|
|
/// <param name="value">The value.</param>
|
|
|
|
public void SetValue<T>(PerspexProperty<T> property, T value) |
|
|
|
{ |
|
|
|
Contract.Requires<NullReferenceException>(property != null); |
|
|
|
|
|
|
|
this.SetValue((PerspexProperty)property, value); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Binds a <see cref="PerspexProperty"/> to an observable.
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="T">The type of the property.</typeparam>
|
|
|
|
/// <param name="property">The property.</param>
|
|
|
|
/// <param name="source">The observable.</param>
|
|
|
|
public void SetValue<T>(PerspexProperty<T> property, IObservable<T> source) |
|
|
|
{ |
|
|
|
Contract.Requires<NullReferenceException>(property != null); |
|
|
|
|
|
|
|
this.SetValue((PerspexProperty)property, source); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Sets a <see cref="PerspexProperty"/> value.
|
|
|
|
/// </summary>
|
|
|
|
@ -351,23 +377,8 @@ namespace Perspex |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
v = new PriorityValue(); |
|
|
|
v = this.CreatePriorityValue(property); |
|
|
|
this.values.Add(property, v); |
|
|
|
|
|
|
|
v.Subscribe(x => |
|
|
|
{ |
|
|
|
object oldValue = (x.Item1 == PerspexProperty.UnsetValue) ? |
|
|
|
this.GetDefaultValue(property) : |
|
|
|
x.Item1; |
|
|
|
object newValue = (x.Item2 == PerspexProperty.UnsetValue) ? |
|
|
|
this.GetDefaultValue(property) : |
|
|
|
x.Item2; |
|
|
|
|
|
|
|
if (!object.Equals(oldValue, newValue)) |
|
|
|
{ |
|
|
|
this.RaisePropertyChanged(property, oldValue, newValue); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
if (binding == null) |
|
|
|
@ -377,33 +388,46 @@ namespace Perspex |
|
|
|
else |
|
|
|
{ |
|
|
|
v.SetLocalBinding(binding); |
|
|
|
|
|
|
|
this.Log().Debug(string.Format( |
|
|
|
"Bound value of {0}.{1} (#{2:x8})", |
|
|
|
this.GetType().Name, |
|
|
|
property.Name, |
|
|
|
this.GetHashCode())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Sets a <see cref="PerspexProperty"/> value.
|
|
|
|
/// Binds a <see cref="PerspexProperty"/> to an style.
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="T">The type of the property.</typeparam>
|
|
|
|
/// <param name="property">The property.</param>
|
|
|
|
/// <param name="value">The value.</param>
|
|
|
|
public void SetValue<T>(PerspexProperty<T> property, T value) |
|
|
|
/// <param name="value">The activated value.</param>
|
|
|
|
/// <param name="activator">An observable which activates the value.</param>
|
|
|
|
/// <remarks>
|
|
|
|
/// Style bindings have a lower precedence than local value bindings. They are toggled
|
|
|
|
/// on or off by <paramref name="activator"/> and can be unbound by the activator
|
|
|
|
/// completing.
|
|
|
|
/// </remarks>
|
|
|
|
public void SetValue(PerspexProperty property, object value, IObservable<bool> activator) |
|
|
|
{ |
|
|
|
Contract.Requires<NullReferenceException>(property != null); |
|
|
|
Contract.Requires<NullReferenceException>(activator != null); |
|
|
|
|
|
|
|
this.SetValue((PerspexProperty)property, value); |
|
|
|
} |
|
|
|
PriorityValue v; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Binds a <see cref="PerspexProperty"/> to an observable.
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="T">The type of the property.</typeparam>
|
|
|
|
/// <param name="property">The property.</param>
|
|
|
|
/// <param name="source">The observable.</param>
|
|
|
|
public void SetValue<T>(PerspexProperty<T> property, IObservable<T> source) |
|
|
|
{ |
|
|
|
Contract.Requires<NullReferenceException>(property != null); |
|
|
|
if (!this.values.TryGetValue(property, out v)) |
|
|
|
{ |
|
|
|
v = this.CreatePriorityValue(property); |
|
|
|
this.values.Add(property, v); |
|
|
|
} |
|
|
|
|
|
|
|
this.SetValue((PerspexProperty)property, source); |
|
|
|
v.AddStyle(activator, value); |
|
|
|
|
|
|
|
this.Log().Debug(string.Format( |
|
|
|
"Bound value of {0}.{1} (#{2:x8}) to style", |
|
|
|
this.GetType().Name, |
|
|
|
property.Name, |
|
|
|
this.GetHashCode())); |
|
|
|
} |
|
|
|
|
|
|
|
private static IObservable<object> BoxObservable<T>(IObservable<T> observable) |
|
|
|
@ -445,6 +469,35 @@ namespace Perspex |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
private PriorityValue CreatePriorityValue(PerspexProperty property) |
|
|
|
{ |
|
|
|
PriorityValue result = new PriorityValue(); |
|
|
|
|
|
|
|
result.Subscribe(x => |
|
|
|
{ |
|
|
|
object oldValue = (x.Item1 == PerspexProperty.UnsetValue) ? |
|
|
|
this.GetDefaultValue(property) : |
|
|
|
x.Item1; |
|
|
|
object newValue = (x.Item2 == PerspexProperty.UnsetValue) ? |
|
|
|
this.GetDefaultValue(property) : |
|
|
|
x.Item2; |
|
|
|
|
|
|
|
if (!object.Equals(oldValue, newValue)) |
|
|
|
{ |
|
|
|
this.RaisePropertyChanged(property, oldValue, newValue); |
|
|
|
|
|
|
|
this.Log().Debug(string.Format( |
|
|
|
"Set value of {0}.{1} (#{2:x8}) to {3}", |
|
|
|
this.GetType().Name, |
|
|
|
property.Name, |
|
|
|
this.GetHashCode(), |
|
|
|
newValue)); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
private object GetDefaultValue(PerspexProperty property) |
|
|
|
{ |
|
|
|
if (property.Inherits && this.inheritanceParent != null) |
|
|
|
@ -493,42 +546,6 @@ namespace Perspex |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//private void SetValueImpl(PerspexProperty property, object value)
|
|
|
|
//{
|
|
|
|
// Contract.Requires<NullReferenceException>(property != null);
|
|
|
|
|
|
|
|
// if (!property.IsValidValue(value))
|
|
|
|
// {
|
|
|
|
// throw new InvalidOperationException("Invalid value for " + property.Name);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// object oldValue = this.GetValue(property);
|
|
|
|
|
|
|
|
// if (!object.Equals(oldValue, value))
|
|
|
|
// {
|
|
|
|
// string valueString = value.ToString();
|
|
|
|
|
|
|
|
// if (value == PerspexProperty.UnsetValue)
|
|
|
|
// {
|
|
|
|
// valueString = "[Unset]";
|
|
|
|
// this.values.Remove(property);
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// this.values[property] = value;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// this.RaisePropertyChanged(property, oldValue, value);
|
|
|
|
|
|
|
|
// this.Log().Debug(string.Format(
|
|
|
|
// "Set value of {0}.{1} (#{2:x8}) to '{3}'",
|
|
|
|
// this.GetType().Name,
|
|
|
|
// property.Name,
|
|
|
|
// this.GetHashCode(),
|
|
|
|
// valueString));
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
private class Binding |
|
|
|
{ |
|
|
|
public object Observable { get; set; } |
|
|
|
|