예제 #1
0
 /// <summary>Creates a new <see cref="TriggerSink"/> instance.</summary>
 public TriggerSink(BplBindingTrigger trigger, BplPropertyPath path) {
    Trigger = trigger;
    Path = path;
 }
예제 #2
0
 // converts the given BPL property path to a WPF property path
 private string _toBindingPathString(BplPropertyPath path) {
    var parts = new string[path.Count];
    for (var i = 0; i < path.Count; i++) {
       var segment = path[i];
       var period = (i < path.Count - 1 ? "." : "");
       if (segment.IsA<BplPropertyPath.SingleItemSegment>()) {
          parts[i] = segment.Name + period;
       } else if (segment.IsA<BplPropertyPath.IndexedItemSegment>()) {
          var index = ((BplPropertyPath.IndexedItemSegment)segment).Index;
          parts[i] = segment.Name + "[" + index + "]" + period;
       } else if (segment.IsA<BplPropertyPath.CurrentItemSegment>()) {
          parts[i] = segment.Name + "/";
       } else if (segment.IsA<BplPropertyPath.CollectionSegment>()) {
          parts[i] = segment.Name + ".LastChange";
       }
    }
    return parts.Join("");
 }
예제 #3
0
 // Gets the value at the given property path segment
 private object _getSegmentValue(BplObject source, BplPropertyPath.PathSegment segment) {
    if (source != null) {
       var property = source.Class.GetProperty(segment.Name);
       if (property != null) {
          var value = property.GetValue(source);
          if (segment.IsA<BplPropertyPath.SingleItemSegment>()) {
             return value;
          } else {
             var collection = value as IBplCollection;
             if (collection != null) {
                if (segment.IsA<BplPropertyPath.CollectionSegment>()) {
                   return collection;
                } else if (segment.IsA<BplPropertyPath.IndexedItemSegment>()) {
                   var index = ((BplPropertyPath.IndexedItemSegment)segment).Index;
                   if (index >= 0 && index < collection.Count) {
                      return collection[index];
                   }
                } else if (segment.IsA<BplPropertyPath.CurrentItemSegment>()) {
                   var collectionView = CollectionViewSource.GetDefaultView(collection);
                   if (collectionView != null) {
                      return collectionView.CurrentItem;
                   }
                }
             }
          }
       }
    }
    return DependencyProperty.UnsetValue;
 }
예제 #4
0
 // Gets the value at the end of the given property path
 private object _getPathValue(BplObject source, BplPropertyPath path) {
    var lastSource = _getLastSource(source, path);
    if (lastSource != null) {
       var value = _getSegmentValue(lastSource, path.LastSegment);
       if (value != DependencyProperty.UnsetValue) return value;
    }
    return null;
 }
예제 #5
0
 // Traverses the path and returns the most immediate source (the last object on the path before the actual property value)
 private BplObject _getLastSource(BplObject source, BplPropertyPath path) {
    if (source == null || path.Count == 0) return null;
    for (var i = 0; i < path.Count - 1; i++) {
       source = _getSegmentValue(source, path[i]) as BplObject;
       if (source == null) break;
    }
    return source;
 }
예제 #6
0
 // Gets the BPL change data that corresponds to the given property path and change event
 private BplChange _getChangeData(BplObject source, BplPropertyPath path, DependencyPropertyChangedEventArgs e) {
    if (e.NewValue.IsA<BplCollectionChange>()) {
       return (BplChange)e.NewValue;
    } else {
       var lastSource = _getLastSource(source, path);
       if (lastSource != null) {
          var lastProperty = lastSource.Class.GetProperty(path.LastSegment.Name);
          if (lastProperty != null && !lastProperty.IsCollection && !lastProperty.IsCalculated) {
             return new BplPropertyChange(lastSource, lastProperty, e.OldValue, e.NewValue);
          }
       }
       return null;
    }
 }