PropertyMetadata.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System;
  4. using Avalonia.Data;
  5. namespace Avalonia
  6. {
  7. /// <summary>
  8. /// Base class for avalonia property metadata.
  9. /// </summary>
  10. public class PropertyMetadata
  11. {
  12. private BindingMode _defaultBindingMode;
  13. /// <summary>
  14. /// Initializes a new instance of the <see cref="PropertyMetadata"/> class.
  15. /// </summary>
  16. /// <param name="defaultBindingMode">The default binding mode.</param>
  17. public PropertyMetadata(
  18. BindingMode defaultBindingMode = BindingMode.Default)
  19. {
  20. _defaultBindingMode = defaultBindingMode;
  21. }
  22. /// <summary>
  23. /// Gets the default binding mode for the property.
  24. /// </summary>
  25. public BindingMode DefaultBindingMode
  26. {
  27. get
  28. {
  29. return _defaultBindingMode == BindingMode.Default ?
  30. BindingMode.OneWay : _defaultBindingMode;
  31. }
  32. }
  33. /// <summary>
  34. /// Merges the metadata with the base metadata.
  35. /// </summary>
  36. /// <param name="baseMetadata">The base metadata to merge.</param>
  37. /// <param name="property">The property to which the metadata is being applied.</param>
  38. public virtual void Merge(
  39. PropertyMetadata baseMetadata,
  40. AvaloniaProperty property)
  41. {
  42. if (_defaultBindingMode == BindingMode.Default)
  43. {
  44. _defaultBindingMode = baseMetadata.DefaultBindingMode;
  45. }
  46. }
  47. }
  48. }