DefaultPlatformProvider.cs 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. namespace Caliburn.Micro.Core {
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Threading.Tasks;
  5. /// <summary>
  6. /// Default implementation for <see cref="IPlatformProvider"/> that does no platform enlightenment.
  7. /// </summary>
  8. public class DefaultPlatformProvider : IPlatformProvider {
  9. /// <summary>
  10. /// Indicates whether or not the framework is in design-time mode.
  11. /// </summary>
  12. public bool InDesignMode {
  13. get { return true; }
  14. }
  15. /// <summary>
  16. /// Executes the action on the UI thread asynchronously.
  17. /// </summary>
  18. /// <param name="action">The action to execute.</param>
  19. public void BeginOnUIThread(Action action) {
  20. action();
  21. }
  22. /// <summary>
  23. /// Executes the action on the UI thread asynchronously.
  24. /// </summary>
  25. /// <param name="action">The action to execute.</param>
  26. /// <returns></returns>
  27. public Task OnUIThreadAsync(Action action) {
  28. return Task.Factory.StartNew(action);
  29. }
  30. /// <summary>
  31. /// Executes the action on the UI thread.
  32. /// </summary>
  33. /// <param name="action">The action to execute.</param>
  34. public void OnUIThread(Action action) {
  35. action();
  36. }
  37. /// <summary>
  38. /// Used to retrieve the root, non-framework-created view.
  39. /// </summary>
  40. /// <param name="view">The view to search.</param>
  41. /// <returns>
  42. /// The root element that was not created by the framework.
  43. /// </returns>
  44. /// <remarks>
  45. /// In certain instances the services create UI elements.
  46. /// For example, if you ask the window manager to show a UserControl as a dialog, it creates a window to host the UserControl in.
  47. /// The WindowManager marks that element as a framework-created element so that it can determine what it created vs. what was intended by the developer.
  48. /// Calling GetFirstNonGeneratedView allows the framework to discover what the original element was.
  49. /// </remarks>
  50. public object GetFirstNonGeneratedView(object view) {
  51. return view;
  52. }
  53. /// <summary>
  54. /// Executes the handler the fist time the view is loaded.
  55. /// </summary>
  56. /// <param name="view">The view.</param>
  57. /// <param name="handler">The handler.</param>
  58. /// <returns>true if the handler was executed immediately; false otherwise</returns>
  59. public void ExecuteOnFirstLoad(object view, Action<object> handler) {
  60. handler(view);
  61. }
  62. /// <summary>
  63. /// Executes the handler the next time the view's LayoutUpdated event fires.
  64. /// </summary>
  65. /// <param name="view">The view.</param>
  66. /// <param name="handler">The handler.</param>
  67. public void ExecuteOnLayoutUpdated(object view, Action<object> handler) {
  68. handler(view);
  69. }
  70. /// <summary>
  71. /// Get the close action for the specified view model.
  72. /// </summary>
  73. /// <param name="viewModel">The view model to close.</param>
  74. /// <param name="views">The associated views.</param>
  75. /// <param name="dialogResult">The dialog result.</param>
  76. /// <returns>
  77. /// An <see cref="Action" /> to close the view model.
  78. /// </returns>
  79. public Action GetViewCloseAction(object viewModel, ICollection<object> views, bool? dialogResult) {
  80. return () => { };
  81. }
  82. }
  83. }