示例#1
0
        public override void OnApplyTemplate()
        {
            monthControl      = this.GetTemplateChild("MonthControl") as MonthControl;
            dateModel         = monthControl is MonthGridControl ? new DateMonthModel() : new DateRangeModel();
            datePickerControl = this.GetTemplateChild("DatePickerControl") as DatePickerControl;
            dualButtonControl = this.GetTemplateChild("DualButtonControl") as DualButtonControl;
            monthGrid         = this.GetTemplateChild("MonthGrid") as Grid;



            SetGridType((GridType)dualButtonControl.ValueToKey());
            datePickerControl.Month = dateModel.Month;
            datePickerControl.Year  = dateModel.Year;

            //if (dualButtonControl.IsLoaded)
            //{
            //sdg();
            //}
            //else
            //{
            //    dualButtonControl.Loaded += (_, _) => sdg();
            //}

            dualButtonControl.ButtonToggle += DualButtonControl_ButtonToggle;

            this.SelectedItem             = monthControl.SelectedItem;
            datePickerControl.DateChange += DatePickerControl_DateChange;


            void sdg()
            {
                SetGridType((GridType)dualButtonControl.ValueToKey());
                datePickerControl.Month = dateModel.Month;
                datePickerControl.Year  = dateModel.Year;

                //SetMonthControl(monthControl);
                //monthControl.ItemsSource = dateModel.Days;
                //monthControl.SelectedItem = dateModel.Current;
                // dateModel.PropertyChanged += DateModel_PropertyChanged;
            }

            base.OnApplyTemplate();


            void DatePickerControl_DateChange(object sender, DateChangeEventArgs e)
            {
                dateModel.Month           = e.Month;
                dateModel.Year            = e.Year;
                monthControl.ItemsSource  = dateModel.Days;
                monthControl.SelectedItem = dateModel.Current;
            }
        }
        private static (ComboBox comboBox, ViewsMasterDetailControl viewsDetailControl, DualButtonControl dualButtonControl) CreateChildren()
        {
            var comboBox = new AssemblyComboBox();

            DockPanel.SetDock(comboBox, Dock.Top);
            Binding binding = new()
            {
                Path   = new PropertyPath(nameof(ComboBox.SelectedValue)),
                Source = comboBox
            };

            var viewsDetailControl = new ViewsMasterDetailControl {
            };

            BindingOperations.SetBinding(viewsDetailControl, ViewsMasterDetailControl.AssemblyProperty, binding);

            var dualButtonControl = new DualButtonControl
            {
                Main      = DemoType.UserControl,
                Alternate = DemoType.ResourceDictionary
            };

            var first = DualButtonEntity.Select.First();

            if (first == null)
            {
                first = new DualButtonEntity {
                    DemoType = DemoType.UserControl
                };
                first.Insert();
            }

            dualButtonControl.Value = dualButtonControl.KeyToValue(viewsDetailControl.DemoType = comboBox.DemoType = first.DemoType);

            dualButtonControl.ButtonToggle += DualButtonControl_ButtonToggle;
            DockPanel.SetDock(dualButtonControl, Dock.Top);

            return(comboBox, viewsDetailControl, dualButtonControl);

            void DualButtonControl_ButtonToggle(object sender, SwitchControl.ToggleEventArgs size)
            {
                var demoType = Enum.Parse <DemoType>(size.Key.ToString());

                viewsDetailControl.DemoType = comboBox.DemoType = first.DemoType = demoType;
                first.Update();
            }
        }
    }
示例#3
0
        /// <summary>
        ///     Builds the driver and operators controls based of off their ControlSchemas
        /// </summary>
        /// <param name="config">The main program's instance of the config</param>
        public static void BuildControlSchema(Config config)
        {
            if (config == null)
            {
                return;
            }

            ControlCollection.Instance.CleanCollection();

            #region Driver_Setup

            var leftDriverConfig = config.DriverConfig.LeftDriveControlSchema;
            var leftDriveControl = new AxisControl(leftDriverConfig.Name, config.DriverConfig.Driver,
                                                   leftDriverConfig.Axis, leftDriverConfig.FitFunction, leftDriverConfig.Reversed,
                                                   leftDriverConfig.DeadZone, config.DriverConfig.LeftDriveControlSchema.IsEnabled,
                                                   leftDriverConfig.PowerMultiplier, leftDriverConfig.FitPower);

            if (leftDriverConfig.Debug)
            {
                leftDriveControl.Debug = true;
            }

            foreach (var binding in leftDriverConfig.Bindings)
            {
                leftDriveControl.AddComponent(config.ActiveCollection.Get(binding));
            }

            ControlCollection.Instance.AddDriverControl(leftDriveControl);

            var rightDriverConfig = config.DriverConfig.RightDriveControlSchema;
            var rightDriveControl = new AxisControl(rightDriverConfig.Name, config.DriverConfig.Driver,
                                                    rightDriverConfig.Axis, rightDriverConfig.FitFunction, rightDriverConfig.Reversed,
                                                    rightDriverConfig.DeadZone, config.DriverConfig.RightDriveControlSchema.IsEnabled,
                                                    rightDriverConfig.PowerMultiplier, rightDriverConfig.FitPower);

            if (rightDriverConfig.Debug)
            {
                rightDriveControl.Debug = true;
            }

            foreach (var binding in rightDriverConfig.Bindings)
            {
                rightDriveControl.AddComponent(config.ActiveCollection.Get(binding));
            }

            ControlCollection.Instance.AddDriverControl(rightDriveControl);

            //load auxillary controls that the driver may have
            foreach (var s in config.DriverConfig.ControlsData)
            {
                switch (s.ControlType)
                {
                case ControlType.Axis:
                    var axisControl = new AxisControl(s.Name, config.DriverConfig.Driver,
                                                      s.Axis, MotorControlFitFunction.Linear, s.Reversed, s.DeadZone, s.IsEnabled,
                                                      s.PowerMultiplier);

                    foreach (var binding in s.Bindings)
                    {
                        axisControl.AddComponent(config.ActiveCollection.Get(binding));
                    }

                    ControlCollection.Instance.AddDriverControl(axisControl);

                    if (s.Debug)
                    {
                        axisControl.Debug = true;
                    }

                    break;

                case ControlType.Button:
                    var btnControl = new ButtonControl(s.Name, config.DriverConfig.Driver,
                                                       s.ButtonA, s.Reversed, s.IsEnabled, s.ActOnRelease, s.PowerMultiplier);

                    foreach (var binding in s.Bindings)
                    {
                        btnControl.AddComponent(config.ActiveCollection.Get(binding));
                    }

                    ControlCollection.Instance.AddDriverControl(btnControl);

                    if (s.Debug)
                    {
                        btnControl.Debug = true;
                    }

                    break;

                case ControlType.DualButton:
                    var dualBtnControl = new DualButtonControl(s.Name, config.DriverConfig.Driver,
                                                               s.ButtonA, s.ButtonB, s.Reversed, s.IsEnabled, s.PowerMultiplier);

                    foreach (var binding in s.Bindings)
                    {
                        dualBtnControl.AddComponent(config.ActiveCollection.Get(binding));
                    }

                    ControlCollection.Instance.AddDriverControl(dualBtnControl);

                    if (s.Debug)
                    {
                        dualBtnControl.Debug = true;
                    }

                    break;

                case ControlType.ToggleButton:
                    var toggleBtnControl = new ToggleButtonControl(s.Name, config.DriverConfig.Driver,
                                                                   s.ButtonA, s.Reversed, s.IsEnabled, s.PowerMultiplier);

                    foreach (var binding in s.Bindings)
                    {
                        toggleBtnControl.AddComponent(config.ActiveCollection.Get(binding));
                    }

                    ControlCollection.Instance.AddDriverControl(toggleBtnControl);

                    if (s.Debug)
                    {
                        toggleBtnControl.Debug = true;
                    }

                    break;
                }
            }

            #endregion Driver_Setup

            #region Operator_Setup

            foreach (var s in config.OperatorConfig.ControlsData)
            {
                switch (s.ControlType)
                {
                case ControlType.Axis:
                    var axisControl = new AxisControl(s.Name,
                                                      config.OperatorConfig.Operator,
                                                      s.Axis, MotorControlFitFunction.Linear, s.Reversed, s.DeadZone, s.IsEnabled,
                                                      s.PowerMultiplier);

                    foreach (var binding in s.Bindings)
                    {
                        axisControl.AddComponent(config.ActiveCollection.Get(binding));
                    }

                    ControlCollection.Instance.AddOperatorControl(axisControl);

                    if (s.Debug)
                    {
                        axisControl.Debug = true;
                    }

                    break;

                case ControlType.Button:
                    var btnControl = new ButtonControl(s.Name, config.OperatorConfig.Operator,
                                                       s.ButtonA, s.Reversed, s.IsEnabled, s.ActOnRelease, s.PowerMultiplier);

                    foreach (var binding in s.Bindings)
                    {
                        btnControl.AddComponent(config.ActiveCollection.Get(binding));
                    }

                    ControlCollection.Instance.AddOperatorControl(btnControl);

                    if (s.Debug)
                    {
                        btnControl.Debug = true;
                    }

                    break;

                case ControlType.DualButton:
                    var dualBtnControl = new DualButtonControl(s.Name, config.OperatorConfig.Operator,
                                                               s.ButtonA, s.ButtonB, s.Reversed, s.IsEnabled, s.PowerMultiplier);

                    foreach (var binding in s.Bindings)
                    {
                        dualBtnControl.AddComponent(config.ActiveCollection.Get(binding));
                    }

                    ControlCollection.Instance.AddOperatorControl(dualBtnControl);

                    if (s.Debug)
                    {
                        dualBtnControl.Debug = true;
                    }

                    break;

                case ControlType.ToggleButton:
                    var toggleBtnControl = new ToggleButtonControl(s.Name, config.OperatorConfig.Operator,
                                                                   s.ButtonA, s.Reversed, s.IsEnabled, s.PowerMultiplier);

                    foreach (var binding in s.Bindings)
                    {
                        toggleBtnControl.AddComponent(config.ActiveCollection.Get(binding));
                    }

                    ControlCollection.Instance.AddOperatorControl(toggleBtnControl);

                    if (s.Debug)
                    {
                        toggleBtnControl.Debug = true;
                    }

                    break;
                }
            }

            #endregion Operator_Setup
        }