ElementConvention.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #if XFORMS
  2. namespace Caliburn.Micro.Core.Xamarin.Forms
  3. #else
  4. namespace Caliburn.Micro
  5. #endif
  6. {
  7. using System;
  8. using System.Reflection;
  9. #if WinRT81
  10. using Windows.UI.Xaml;
  11. using TriggerBase = Microsoft.Xaml.Interactivity.IBehavior;
  12. #elif XFORMS
  13. using global::Xamarin.Forms;
  14. using DependencyObject = global::Xamarin.Forms.BindableObject;
  15. using DependencyProperty = global::Xamarin.Forms.BindableProperty;
  16. using FrameworkElement = global::Xamarin.Forms.VisualElement;
  17. #else
  18. using System.Windows;
  19. using TriggerBase = System.Windows.Interactivity.TriggerBase;
  20. #endif
  21. /// <summary>
  22. /// Represents the conventions for a particular element type.
  23. /// </summary>
  24. public class ElementConvention
  25. {
  26. /// <summary>
  27. /// The type of element to which the conventions apply.
  28. /// </summary>
  29. public Type ElementType;
  30. /// <summary>
  31. /// Gets the default property to be used in binding conventions.
  32. /// </summary>
  33. public Func<DependencyObject, DependencyProperty> GetBindableProperty;
  34. /// <summary>
  35. /// The default trigger to be used when wiring actions on this element.
  36. /// </summary>
  37. public Func<TriggerBase> CreateTrigger;
  38. /// <summary>
  39. /// The default property to be used for parameters of this type in actions.
  40. /// </summary>
  41. public string ParameterProperty;
  42. /// <summary>
  43. /// Applies custom conventions for elements of this type.
  44. /// </summary>
  45. /// <remarks>Pass the view model type, property path, property instance, framework element and its convention.</remarks>
  46. public Func<Type, string, PropertyInfo, FrameworkElement, ElementConvention, bool> ApplyBinding =
  47. (viewModelType, path, property, element, convention) => ConventionManager.SetBindingWithoutBindingOverwrite(viewModelType, path, property, element, convention, convention.GetBindableProperty(element));
  48. }
  49. }