using System.Windows; using System.Windows.Media; using Caliburn.Metadata; using Caliburn.Services; namespace Caliburn.Messaging { public class ActionMessageSender { private readonly ActionMessage _message; private readonly DependencyObject _source; public ActionMessageSender(DependencyObject source, ActionMessage message) { _message = message; _source = source; } public virtual void Send() { Send(_source, _source); } protected virtual void Send(DependencyObject currentSource, DependencyObject originalSource) { if(currentSource == null) return; IPresenterManager presenterManager = DI.Resolve(); PresenterBinding binding = presenterManager.GetBinding(currentSource); if(binding == PresenterBinding.NotFound) return; object presenter = binding.Presenter; PresenterInfo presenterInfo = presenterManager.GetInfo(presenter.GetType()); ActionInfo actionInfo = presenterInfo.FindAction(_message.Action); if(actionInfo != null) actionInfo.Execute(presenter, _message, originalSource); else Send(VisualTreeHelper.GetParent(binding.Target), originalSource); } } }