/// <summary> /// Gets the adorners used with this control during a hard selection (left-click). /// Currently used to create an adorner that allows browsing to two channel paths /// </summary> /// <returns>An enumerable collection of hard select adorners.</returns> public override IEnumerable <Adorner> GetHardSelectAdorners() { var adorners = new Collection <Adorner>(); var toolbar = new FloatingToolBar(); // if there is no model then don't return adorners if (Model == null) { return(adorners); } // create a new instance of our adorner class and add it to the floating toolbar which is used as the container for the adorner var control = new TwoChannelAdorner(DesignerNodeHelpers.GetVisualForViewModel(this)); toolbar.ToolBar = control; adorners.Add(new ControlAdorner(DesignerNodeHelpers.GetVisualForViewModel(this), toolbar, Placement.BelowCenter)); return(adorners); }
/// <summary> /// Constructs a new instance of the TwoChannelAdorner class /// </summary> /// <param name="adornedElement">The visual element this adorner is attached to.</param> public TwoChannelAdorner(PlatformVisual adornedElement) { InitializeComponent(); // set the data context for the control to itself. This lets us bind to the commands by name instead of having to use a more advanced binding DataContext = this; Model = DesignerNodeHelpers.GetModelForVisual(adornedElement) as VisualModel; // set up the commands which are used by the adorner buttonsf LoadFirstPopupCommand = new RelayCommand(ExecuteLoadFirstPopup); LoadSecondPopupCommand = new RelayCommand(ExecuteLoadSecondPopup); // Hook up event handlers. We set up event handlers for when keys are pressed on the adorner as well as when the properties change on either of the channel // selection popups WeakEventManager <UIElement, KeyEventArgs> .AddHandler(this, "KeyDown", HandleKeyDown); WeakEventManager <UIElement, KeyEventArgs> .AddHandler(this, "KeyUp", HandleKeyUp); WeakEventManager <ChannelPopup, PropertyChangedEventArgs> .AddHandler(FirstUiSdfPopup, "PropertyChanged", FirstChannelPropertyChanged); WeakEventManager <ChannelPopup, PropertyChangedEventArgs> .AddHandler(SecondUiSdfPopup, "PropertyChanged", SecondChannelPropertyChanged); // add this adorner as an observer of the model Model.AddObserver(this); FirstTextControl.Text = ((PulseWidthModulationControlModel)Model).FrequencyChannel; SecondTextControl.Text = ((PulseWidthModulationControlModel)Model).DutyCycleChannel; }