示例#1
0
        private void RegisterControls(Dictionary <DependencyObject, string> controlDict)
        {
            foreach (var control in controlDict.Keys)
            {
                if (!(control is UIElement))
                {
                    continue;
                }

                UIElement uiElem = control as UIElement;
                uiElem.MouseEnter += (s, e) => SetActiveControl(s as UIElement, true);
                uiElem.MouseLeave += (s, e) => SetActiveControl(s as UIElement, false);

                var address = OscAddress.GetAddress(control);
                var key     = Parameters.Pack(address);
                controls[key] = control;

                var lightKnob = control as LightKnob;
                if (lightKnob != null)
                {
                    DependencyPropertyDescriptor.FromProperty(LightKnob.ValueProperty, typeof(LightKnob))
                    .AddValueChanged(lightKnob, (s, e) => SendValue(address, lightKnob.Value));
                }

                var listbox = control as ListBox;
                if (listbox != null)
                {
                    DependencyPropertyDescriptor.FromProperty(Selector.SelectedItemProperty, typeof(ListBox))
                    .AddValueChanged(listbox, (s, e) => SendValue(address, ((KeyValuePair <int, string>)listbox.SelectedItem).Key));
                }

                var toggle = control as ToggleButton;
                if (toggle != null)
                {
                    DependencyPropertyDescriptor.FromProperty(ToggleButton.IsCheckedProperty, typeof(ToggleButton))
                    .AddValueChanged(toggle, (s, e) => SendValue(address, toggle.IsChecked.GetValueOrDefault() ? 1 : 0));
                }

                var spinner = control as Spinner;
                if (spinner != null)
                {
                    DependencyPropertyDescriptor.FromProperty(Spinner.ValueProperty, typeof(Spinner))
                    .AddValueChanged(spinner, (s, e) => SendValue(address, spinner.Value));
                }
            }
        }
示例#2
0
        private void SetActiveControl(UIElement uiElement, bool isActive)
        {
            lock (updateLock)
            {
                if (isActive)
                {
                    currentControl = uiElement;
                    var address = OscAddress.GetAddress(uiElement);
                    var tuple   = Parameters.ParseAddress(address);
                    SetActiveParameter(tuple.Item1, tuple.Item2);

                    RequestVisual(tuple.Item1, tuple.Item2);
                    RequestParameter(tuple.Item1, tuple.Item2);
                }
                else if (currentControl.Equals(uiElement))
                {
                    currentControl = null;
                    ClearActiveParameter();
                    VisualGeometry = null;
                }
            }
        }