init
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Microsoft.Practices.Prism.Events;
|
||||
using Microsoft.Practices.ServiceLocation;
|
||||
using Microsoft.Windows.Controls.Ribbon;
|
||||
|
||||
namespace DTS.Common.RibbonControl
|
||||
{
|
||||
public class RibbonControlSelectionChangeBehavior : System.Windows.Interactivity.Behavior<Ribbon>
|
||||
{
|
||||
public static readonly DependencyProperty TargetRibbonProperty = DependencyProperty.Register("TargetRibbonControl", typeof(Ribbon), typeof(RibbonControlSelectionChangeBehavior), new PropertyMetadata(null));
|
||||
|
||||
private IEventAggregator _eventAggregator;
|
||||
|
||||
public Ribbon TargetRibbonControl
|
||||
{
|
||||
get => (Ribbon)GetValue(TargetRibbonProperty);
|
||||
set => SetValue(TargetRibbonProperty, value);
|
||||
}
|
||||
|
||||
protected override void OnAttached()
|
||||
{
|
||||
base.OnAttached();
|
||||
AssociatedObject.SelectionChanged += Ribbon_SelectionChanged;
|
||||
|
||||
if (_eventAggregator == null)
|
||||
_eventAggregator = ServiceLocator.Current.GetInstance<IEventAggregator>();
|
||||
}
|
||||
|
||||
protected override void OnDetaching()
|
||||
{
|
||||
base.OnDetaching();
|
||||
AssociatedObject.SelectionChanged -= Ribbon_SelectionChanged;
|
||||
}
|
||||
|
||||
void Ribbon_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (e.AddedItems.Count > 0)
|
||||
_eventAggregator.GetEvent<RibbonControlSelectionChanged>().Publish(new RibbonControlSelectionEventArgs(RibbonControlOperation.AddedItem, e.AddedItems[0]));
|
||||
|
||||
if (e.RemovedItems.Count > 0)
|
||||
_eventAggregator.GetEvent<RibbonControlSelectionChanged>().Publish(new RibbonControlSelectionEventArgs(RibbonControlOperation.RemovedItem, e.RemovedItems[0]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user