public void Binding_OnParse_Invoke_CallsParse(bool formattingEnabled, ConvertEventArgs eventArgs, object expectedValue)
        {
            var binding = new SubBinding("propertyName", new object(), "dataMember")
            {
                FormattingEnabled = formattingEnabled
            };

            // No handler.
            object oldValue = eventArgs?.Value;

            binding.OnParse(eventArgs);
            Assert.Equal(expectedValue, eventArgs?.Value);

            // Handler.
            int callCount = 0;
            ConvertEventHandler handler = (sender, e) =>
            {
                Assert.Equal(binding, sender);
                Assert.Same(eventArgs, e);
                callCount++;
            };

            binding.Parse += handler;
            if (eventArgs != null)
            {
                eventArgs.Value = oldValue;
            }
            binding.OnParse(eventArgs);
            Assert.Equal(expectedValue, eventArgs?.Value);
            Assert.Equal(1, callCount);

            // Should not call if the handler is removed.
            binding.Parse -= handler;
            if (eventArgs != null)
            {
                eventArgs.Value = oldValue;
            }
            binding.OnParse(eventArgs);
            Assert.Equal(expectedValue, eventArgs?.Value);
            Assert.Equal(1, callCount);
        }
        protected virtual void BindProperties(Control target, string targetProperty, string sourceProperty, ConvertEventHandler objectToStringConverter)
        {
            Binding binding = new Binding(targetProperty, Controller, sourceProperty, true);

            binding.Format += objectToStringConverter;
            target.DataBindings.Add(binding);
        }
 /// <summary>
 /// This method and its overloads can be used to simplify adding data bindings to controls contained in
 /// the template.
 /// </summary>
 /// <param name="control">The control to which to add the data binding</param>
 /// <param name="controlProperty">The name of the control property to bind</param>
 /// <param name="dataMember">The property or list to which to bind</param>
 /// <param name="clearBindings">Specify true to clear all existing bindings before adding the new binding
 /// or false to keep all existing bindings.</param>
 /// <param name="formatEvent">An event handler for the binding's <c>Format</c> event</param>
 /// <remarks>This version will only clear the existing data bindings if the <c>clearBindings</c>
 /// parameter is true.  It will also add the specified format event handler to the binding.</remarks>
 /// <returns>The newly created data binding</returns>
 public Binding AddBinding(Control control, string controlProperty, string dataMember, bool clearBindings,
                           ConvertEventHandler formatEvent)
 {
     return(this.AddBinding(control, controlProperty, dataMember, clearBindings, formatEvent, null));
 }
 public Schema(IBindableComponent targetControl, string targetField, object dataStore, string dataField, DataSourceUpdateMode updateMode = DataSourceUpdateMode.OnPropertyChanged, ConvertEventHandler formatter = null, ConvertEventHandler parser = null)
 {
     TargetControl = targetControl; TargetField = targetField; DataStore = dataStore; DataField = dataField; UpdateMode = updateMode; Parser = parser; Formatter = formatter;
 }
        private void PrepareBinding()
        {
            var Config       = Resource.Config;
            var AlterTextCfg = Config.AlterTextCfg;
            var AlterFontCfg = Config.AlterTextCfg.AlterFontCfg;
            ConvertEventHandler FontFormatter = (s, e) => {
                var font     = (Font)e.Value;
                var baseFont = ((Binding)s).Control.Font;
                e.Value = new Font(font.FontFamily, baseFont.Size, font.Style);
            };
            var OneWay  = DataSourceUpdateMode.Never;
            var schemas = new Schema[] {
                new Schema(chkAlterText, "Checked", AlterTextCfg, nameof(AlterTextCfg.Enabled)),
                new Schema(grpAlterText, "Enabled", AlterTextCfg, nameof(AlterTextCfg.Enabled), OneWay),

                new Schema(chkUseBorder, "Checked", AlterTextCfg, nameof(AlterTextCfg.UseBlackBorder)),

                new Schema(chkCustomFont, "Checked", AlterFontCfg, nameof(AlterFontCfg.Enabled)),
                new Schema(grpAlterFont, "Enabled", AlterFontCfg, nameof(AlterFontCfg.Enabled), OneWay),

                new Schema(chkAlterFPSFont, "Checked", AlterFontCfg.FPSFont, nameof(AlterFontCfg.FPSFont.Enabled)),
                new Schema(chkAlterSpellNameFont, "Checked", AlterFontCfg.SpellNameFont, nameof(AlterFontCfg.SpellNameFont.Enabled)),
                new Schema(chkAlterSpellStatisticsFont, "Checked", AlterFontCfg.SpellStatFont, nameof(AlterFontCfg.SpellStatFont.Enabled)),
                new Schema(chkAlterRestFont, "Checked", AlterFontCfg.RestFont, nameof(AlterFontCfg.RestFont.Enabled)),

                new Schema(lblFPSFont, "Enabled", AlterFontCfg.FPSFont, nameof(AlterFontCfg.FPSFont.Enabled), OneWay),
                new Schema(lblSpellFont, "Enabled", AlterFontCfg.SpellNameFont, nameof(AlterFontCfg.SpellNameFont.Enabled), OneWay),
                new Schema(lblSpellStatisticsFont, "Enabled", AlterFontCfg.SpellStatFont, nameof(AlterFontCfg.SpellStatFont.Enabled), OneWay),
                new Schema(lblRestFont, "Enabled", AlterFontCfg.RestFont, nameof(AlterFontCfg.RestFont.Enabled), OneWay),

                new Schema(lblFPSFont, "Text", AlterFontCfg.FPSFont, nameof(AlterFontCfg.FPSFont.FontI), OneWay),
                new Schema(lblRestFont, "Text", AlterFontCfg.RestFont, nameof(AlterFontCfg.RestFont.FontI), OneWay),
                new Schema(lblSpellFont, "Text", AlterFontCfg.SpellNameFont, nameof(AlterFontCfg.SpellNameFont.FontI), OneWay),
                new Schema(lblSpellStatisticsFont, "Text", AlterFontCfg.SpellStatFont, nameof(AlterFontCfg.SpellStatFont.FontI), OneWay),

                new Schema(lblFPSFont, "Font", AlterFontCfg.FPSFont, nameof(AlterFontCfg.FPSFont.FontI), OneWay, FontFormatter),
                new Schema(lblRestFont, "Font", AlterFontCfg.RestFont, nameof(AlterFontCfg.RestFont.FontI), OneWay, FontFormatter),
                new Schema(lblSpellFont, "Font", AlterFontCfg.SpellNameFont, nameof(AlterFontCfg.SpellNameFont.FontI), OneWay, FontFormatter),
                new Schema(lblSpellStatisticsFont, "Font", AlterFontCfg.SpellStatFont, nameof(AlterFontCfg.SpellStatFont.FontI), OneWay, FontFormatter),


                new Schema(chkProtagonistLineColor, "Checked", AlterFontCfg.ProtagonistLineColor, nameof(AlterFontCfg.ProtagonistLineColor.Enabled)),
                new Schema(chkAntagonistLineColor, "Checked", AlterFontCfg.AntagonistLineColor, nameof(AlterFontCfg.AntagonistLineColor.Enabled)),

                new Schema(lblProtagonistLineColor, "Enabled", AlterFontCfg.ProtagonistLineColor, nameof(AlterFontCfg.ProtagonistLineColor.Enabled), OneWay),
                new Schema(lblAntagonistLineColor, "Enabled", AlterFontCfg.AntagonistLineColor, nameof(AlterFontCfg.AntagonistLineColor.Enabled), OneWay),

                new Schema(lblProtagonistLineColor, "Text", AlterFontCfg.ProtagonistLineColor, nameof(AlterFontCfg.ProtagonistLineColor.ColorI), OneWay),
                new Schema(lblAntagonistLineColor, "Text", AlterFontCfg.AntagonistLineColor, nameof(AlterFontCfg.AntagonistLineColor.ColorI), OneWay),
                new Schema(lblProtagonistLineColor, "ForeColor", AlterFontCfg.ProtagonistLineColor, nameof(AlterFontCfg.ProtagonistLineColor.ColorI), OneWay),
                new Schema(lblAntagonistLineColor, "ForeColor", AlterFontCfg.AntagonistLineColor, nameof(AlterFontCfg.AntagonistLineColor.ColorI), OneWay),

                new Schema(chkTachieOnTop, "Checked", Config, nameof(Config.TachieOnTop)),
                new Schema(chkUseSkip, "Checked", Config, nameof(Config.UseSkipPatch)),
            };

            foreach (var schema in schemas)
            {
                var binding = new Binding(
                    schema.TargetField, schema.DataStore, schema.DataField, true, schema.UpdateMode);
                binding.Parse  += schema.Parser;
                binding.Format += schema.Formatter;
                schema.TargetControl.DataBindings.Add(binding);
            }
        }
 private object ParseString(string value)
 {
     try
     {
         ConvertEventHandler convertEventHandler = (ConvertEventHandler)base.Events[InlineEditDataListControl.EventParse];
         if (convertEventHandler != null)
         {
             ConvertEventArgs convertEventArgs = new ConvertEventArgs(value, base.ItemType);
             convertEventHandler(this, convertEventArgs);
             return(convertEventArgs.Value);
         }
         MethodInfo method = base.ItemType.GetMethod("Parse", BindingFlags.Static | BindingFlags.Public, null, new Type[]
         {
             typeof(string)
         }, null);
         if (null != method)
         {
             try
             {
                 return(method.Invoke(null, new object[]
                 {
                     value
                 }));
             }
             catch (TargetInvocationException ex)
             {
                 throw new FormatException(ex.InnerException.Message, ex.InnerException);
             }
         }
         TypeConverter converter = TypeDescriptor.GetConverter(base.ItemType);
         if (converter != null && converter.CanConvertFrom(typeof(string)))
         {
             return(converter.ConvertFrom(null, CultureInfo.CurrentUICulture, value));
         }
         ConstructorInfo constructor = base.ItemType.GetConstructor(new Type[]
         {
             typeof(string)
         });
         if (null != constructor)
         {
             try
             {
                 return(constructor.Invoke(new object[]
                 {
                     value
                 }));
             }
             catch (TargetInvocationException ex2)
             {
                 throw new FormatException(ex2.InnerException.Message, ex2.InnerException);
             }
         }
         return(value);
     }
     catch (FormatException ex3)
     {
         base.ShowErrorAsync(ex3.Message);
     }
     catch (ArgumentException ex4)
     {
         base.ShowErrorAsync(ex4.Message);
     }
     return(null);
 }
Exemple #7
0
        public static IndicationBinding Create(Control control, string propertyName, object dataSource, string dataMember, ConvertEventHandler additionFormat)
        {
            IndicationBinding binding = new IndicationBinding(propertyName, dataSource, dataMember, false, DataSourceUpdateMode.Never);

            binding.Format += additionFormat;
            control.DataBindings.Add(binding);
            return(binding);
        }
Exemple #8
0
        private void InitializeBindings()
        {
            CreateSettingBinding(chkDisableIntro, "Checked", "DisableIntroVideo");
            CreateSettingBinding(chkDisableNearCulling, "Checked", "DisableNearCulling");
            CreateSettingBinding(chkDisableFarCulling, "Checked", "DisableFarCulling");
            CreateSettingBinding(chkDisableUpdateCulling, "Checked", "DisableUpdateCulling");
            CreateSettingBinding(chkDisableLODReduction, "Checked", "DisableLODReduction");
            CreateSettingBinding(chkHideAllUI, "Checked", "HideUI");
            CreateSettingBinding(chkHideCommandPalette, "Checked", "HideSubpalette");
            CreateSettingBinding(chkHideScreenNotifications, "Checked", "HideScreenNotifications");
            CreateSettingBinding(chkHideEmergencyCodes, "Checked", "HideEmergencyCodes");
            CreateSettingBinding(chkHideHud, "Checked", "HideHud");
            CreateSettingBinding(chkMinimzeToTray, "Checked", "MinimizeToTray");
            CreateSettingBinding(chkCloseToTray, "Checked", "CloseToTray");
            CreateSettingBinding(chkAutomaticUpdates, "Checked", "AutomaticUpdates");
            CreateSettingBinding(chkPromptOnUpdate, "Checked", "PromptOnUpdate");
            CreateSettingBinding(radRunning, "Checked", "RunEnabled");
            CreateSettingBinding(radWalking, "Checked", "WalkEnabled");
            CreateSettingBinding(numRunInputScale, "Value", "RunInputScale");
            CreateSettingBinding(numWalkInputScale, "Value", "WalkInputScale");
            CreateSettingBinding(numFovNormal, "Value", "FovNormal");
            CreateSettingBinding(numFovTPS, "Value", "FovTPS");
            CreateSettingBinding(numFovNPCTalk, "Value", "FovNPCTalk");

            CreateSettingBinding(chkCam1Customize, "Checked", "CustomizeRegularCam");
            CreateSettingBinding(chkCam2Customize, "Checked", "CustomizeShooterCam");
            CreateSettingBinding(pnlCam1Customize, "Enabled", "CustomizeRegularCam");
            CreateSettingBinding(pnlCam2Customize, "Enabled", "CustomizeShooterCam");
            CreateSettingBinding(btnCam1Reset, "Enabled", "CustomizeRegularCam");
            CreateSettingBinding(btnCam2Reset, "Enabled", "CustomizeShooterCam");
            CreateSettingBinding(numCam1Distance, "Value", "RegularCamDistance");
            CreateSettingBinding(numCam1Height, "Value", "RegularCamHeight");
            CreateSettingBinding(numCam2X, "Value", "ShooterCamX");
            CreateSettingBinding(numCam2Y, "Value", "ShooterCamY");
            CreateSettingBinding(numCam2Z, "Value", "ShooterCamZ");
            CreateSettingBinding(numCam2Yaw, "Value", "ShooterCamYaw");
            CreateSettingBinding(numCam2Pitch, "Value", "ShooterCamPitch");
            CreateSettingBinding(numCam2Height, "Value", "ShooterCamHeight");

            CreateSettingBinding(chkCustomizeColors, "Checked", "CustomizeColors");
            CreateSettingBinding(pnlCustomizeColors, "Enabled", "CustomizeColors");
            CreateSettingBinding(btnResetColors, "Enabled", "CustomizeColors");
            CreateSettingBinding(numBrightness, "Value", "Brightness");
            CreateSettingBinding(numContrast, "Value", "Contrast");
            CreateSettingBinding(numSaturation, "Value", "Saturation");
            CreateSettingBinding(numRedBalance, "Value", "RedBalance");
            CreateSettingBinding(numGreenBalance, "Value", "GreenBalance");
            CreateSettingBinding(numBlueBalance, "Value", "BlueBalance");

            ConvertEventHandler parseBy10   = (object s, ConvertEventArgs e) => { e.Value = (decimal)((int)e.Value / 10.0f); };
            ConvertEventHandler formatBy10  = (object s, ConvertEventArgs e) => { e.Value = (int)((decimal)e.Value * 10); };
            ConvertEventHandler parseBy100  = (object s, ConvertEventArgs e) => { e.Value = (decimal)((int)e.Value / 100.0f); };
            ConvertEventHandler formatBy100 = (object s, ConvertEventArgs e) => { e.Value = (int)((decimal)e.Value * 100); };

            CreateTrackBinding(trackRunInputScale, numRunInputScale, parseBy100, formatBy100);
            CreateTrackBinding(trackWalkInputScale, numWalkInputScale, parseBy100, formatBy100);
            CreateTrackBinding(trackCam1Distance, numCam1Distance, parseBy10, formatBy10);
            CreateTrackBinding(trackCam1Height, numCam1Height, parseBy10, formatBy10);
            CreateTrackBinding(trackCam2X, numCam2X, parseBy10, formatBy10);
            CreateTrackBinding(trackCam2Y, numCam2Y, parseBy10, formatBy10);
            CreateTrackBinding(trackCam2Z, numCam2Z, parseBy10, formatBy10);
            CreateTrackBinding(trackCam2Yaw, numCam2Yaw, parseBy10, formatBy10);
            CreateTrackBinding(trackCam2Pitch, numCam2Pitch, parseBy10, formatBy10);
            CreateTrackBinding(trackCam2Height, numCam2Height, parseBy10, formatBy10);
            CreateTrackBinding(trackBrightness, numBrightness, parseBy100, formatBy100);
            CreateTrackBinding(trackContrast, numContrast, parseBy100, formatBy100);
            CreateTrackBinding(trackSaturation, numSaturation, parseBy100, formatBy100);
            CreateTrackBinding(trackRedBalance, numRedBalance, parseBy100, formatBy100);
            CreateTrackBinding(trackGreenBalance, numGreenBalance, parseBy100, formatBy100);
            CreateTrackBinding(trackBlueBalance, numBlueBalance, parseBy100, formatBy100);
        }
        public static Binding CreateManualBinding <T, K>(Control p_ctlControl, Expression <Func <T> > p_expControlProperty, ConvertEventHandler p_cehFormatHandler, object p_objDataSource, Expression <Func <K> > p_expBoundProperty, ConvertEventHandler p_cehParseHandler)
        {
            Binding bdgBinding = new Binding(ObjectHelper.GetPropertyName <T>(p_expControlProperty), p_objDataSource, ObjectHelper.GetPropertyName <K>(p_expBoundProperty), false, DataSourceUpdateMode.Never);

            bdgBinding.Format += p_cehFormatHandler;
            bdgBinding.Parse  += p_cehParseHandler;
            p_ctlControl.DataBindings.Add(bdgBinding);
            bdgBinding.ControlUpdateMode = ControlUpdateMode.Never;
            return(bdgBinding);
        }
Exemple #10
0
        private void CreateTrackBinding(TrackBar track, NumericUpDown numeric, ConvertEventHandler parse, ConvertEventHandler format)
        {
            Binding binding = track.DataBindings.Add("Value", numeric, "Value");

            binding.FormattingEnabled    = false;
            binding.DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;

            if (parse != null)
            {
                binding.Parse += parse;
            }

            if (format != null)
            {
                binding.Format += format;
            }
        }
        /// <summary>
        /// This method and its overloads can be used to simplify adding data bindings to controls contained in
        /// the template.
        /// </summary>
        /// <param name="control">The control to which to add the data binding</param>
        /// <param name="controlProperty">The name of the control property to bind</param>
        /// <param name="dataMember">The property or list to which to bind</param>
        /// <param name="clearBindings">Specify true to clear all existing bindings before adding the new binding
        /// or false to keep all existing bindings.</param>
        /// <param name="formatEvent">An event handler for the binding's <c>Format</c> event if wanted</param>
        /// <param name="parseEvent">An event handler for the binding's <c>Parse</c> event if wanted</param>
        /// <remarks>This version will only clear the existing data bindings if the <c>clearBindings</c>
        /// parameter is true.  It will also add the specified format and parse event handlers to the binding if
        /// they are specified.  Use null if you do not want a particular handler added.</remarks>
        /// <returns>The newly created data binding</returns>
        /// <exception cref="ArgumentNullException">This is thrown if the control parameter is null</exception>
        public Binding AddBinding(Control control, string controlProperty, string dataMember, bool clearBindings,
          ConvertEventHandler formatEvent, ConvertEventHandler parseEvent)
        {
            if(control == null)
                throw new ArgumentNullException("control", LR.GetString("ExNullParameter"));

            Binding b = new Binding(controlProperty, rowSource, dataMember);

            if(formatEvent != null)
                b.Format += formatEvent;

            if(parseEvent != null)
                b.Parse += parseEvent;

            if(clearBindings)
                control.DataBindings.Clear();

            control.DataBindings.Add(b);
            return b;
        }
 /// <summary>
 /// This method and its overloads can be used to simplify adding data bindings to controls contained in
 /// the template.
 /// </summary>
 /// <param name="control">The control to which to add the data binding</param>
 /// <param name="controlProperty">The name of the control property to bind</param>
 /// <param name="dataMember">The property or list to which to bind</param>
 /// <param name="clearBindings">Specify true to clear all existing bindings before adding the new binding
 /// or false to keep all existing bindings.</param>
 /// <param name="formatEvent">An event handler for the binding's <c>Format</c> event</param>
 /// <remarks>This version will only clear the existing data bindings if the <c>clearBindings</c>
 /// parameter is true.  It will also add the specified format event handler to the binding.</remarks>
 /// <returns>The newly created data binding</returns>
 public Binding AddBinding(Control control, string controlProperty, string dataMember, bool clearBindings,
   ConvertEventHandler formatEvent)
 {
     return this.AddBinding(control, controlProperty, dataMember, clearBindings, formatEvent, null);
 }
Exemple #13
0
 public CompleteBinding OnFormat(ConvertEventHandler handler)
 {
     Binding.Format += handler;
     return this;
 }
Exemple #14
0
 public CompleteBinding OnParse(ConvertEventHandler handler)
 {
     Binding.Parse += handler;
     return this;
 }