public override ValidationResult Validate(object value, CultureInfo cultureInfo, BindingExpressionBase owner) { var box = (BaseBox)((BindingExpression)owner).ResolvedSource; var text = (string)value; var pattern = box.RegexPattern; if (string.IsNullOrEmpty(pattern)) { return ValidationResult.ValidResult; } if (string.IsNullOrEmpty(text)) { var formatted = text == null ? "null" : "string.Empty"; return new IsMatchValidationResult(text, pattern, false, $"{formatted} does not match pattern: {pattern}"); } try { if (Regex.IsMatch(text, pattern)) { return ValidationResult.ValidResult; } return new IsMatchValidationResult(text, pattern, false, $"{text} does not match pattern: {pattern}"); } catch (Exception e) { return new IsMatchValidationResult(text, pattern, false, $"{text} does not match pattern: {pattern}. Threw exception: {e.Message}"); } }
//------------------------------------------------------ // // Constructors // //------------------------------------------------------ private BindingExpression(Binding binding, BindingExpressionBase owner) : base(binding, owner) { UseDefaultValueConverter = (ParentBinding.Converter == null); if (TraceData.IsExtendedTraceEnabled(this, TraceDataLevel.ShowPath)) { PropertyPath pp = binding.Path; string path = (pp != null) ? pp.Path : String.Empty; if (String.IsNullOrEmpty(binding.XPath)) { TraceData.Trace(TraceEventType.Warning, TraceData.BindingPath( TraceData.Identify(path))); } else { TraceData.Trace(TraceEventType.Warning, TraceData.BindingXPathAndPath( TraceData.Identify(binding.XPath), TraceData.Identify(path))); } } }
public ToolBarCheckBox(Codon codon, object caller) { ToolTipService.SetShowOnDisabled(this, true); this.codon = codon; this.caller = caller; this.Command = CommandWrapper.GetCommand(codon, caller, true); CommandWrapper wrapper = this.Command as CommandWrapper; if (wrapper != null) { ICheckableMenuCommand cmd = wrapper.GetAddInCommand() as ICheckableMenuCommand; if (cmd != null) { isCheckedBinding = SetBinding(IsCheckedProperty, new Binding("IsChecked") { Source = cmd, Mode = BindingMode.OneWay }); } } if (codon.Properties.Contains("icon")) { var image = PresentationResourceService.GetImage(StringParser.Parse(codon.Properties["icon"])); image.Height = 16; image.SetResourceReference(StyleProperty, ToolBarService.ImageStyleKey); this.Content = image; } else { this.Content = codon.Id; } UpdateText(); SetResourceReference(FrameworkElement.StyleProperty, ToolBar.CheckBoxStyleKey); }
public ToolBarCheckBox(Codon codon, object caller, IEnumerable<ICondition> conditions) { ToolTipService.SetShowOnDisabled(this, true); this.codon = codon; this.caller = caller; this.conditions = conditions; this.Command = CommandWrapper.GetCommand(codon, caller, true, conditions); CommandWrapper wrapper = this.Command as CommandWrapper; if (wrapper != null) { ICheckableMenuCommand cmd = wrapper.GetAddInCommand() as ICheckableMenuCommand; if (cmd != null) { #if ModifiedForAltaxo isCheckedBinding = SetBinding(IsCheckedProperty, new Binding("IsChecked") { Source = cmd, Mode = BindingMode.TwoWay }); #else isCheckedBinding = SetBinding(IsCheckedProperty, new Binding("IsChecked") { Source = cmd, Mode = BindingMode.OneWay }); #endif } } this.Content = ToolBarService.CreateToolBarItemContent(codon); if (codon.Properties.Contains("name")) { this.Name = codon.Properties["name"]; } UpdateText(); SetResourceReference(FrameworkElement.StyleProperty, ToolBar.CheckBoxStyleKey); }
/// <summary> /// Interaction with VM /// </summary> /// <returns></returns> public override ValidationResult Validate(object value, CultureInfo cultureInfo, BindingExpressionBase owner) { var result = base.Validate(value, cultureInfo, owner); var viewmodel = (LoginViewModel)((BindingExpression)owner).DataItem; viewmodel.IsPasswordValid = result.IsValid; return result; }
/// <summary> /// Interaction with VM /// </summary> public override ValidationResult Validate(object value, CultureInfo cultureInfo, BindingExpressionBase owner) { var result = base.Validate(value, cultureInfo, owner); var viewmodel = (FlightControllerAddFlightViewModel)((BindingExpression)owner).DataItem; viewmodel.IsDepartureCountryValid = result.IsValid; return result; }
/// <summary> /// Interaction with VM /// </summary> public override ValidationResult Validate(object value, CultureInfo cultureInfo, BindingExpressionBase owner) { var result = base.Validate(value, cultureInfo, owner); var viewmodel = (AdministratorAddUserViewModel)((BindingExpression)owner).DataItem; viewmodel.IsLastNameValid = result.IsValid; return result; }
//------------------------------------------------------ // // Constructors // //------------------------------------------------------ /// <summary> Constructor </summary> private MultiBindingExpression(MultiBinding binding, BindingExpressionBase owner) : base(binding, owner) { int count = binding.Bindings.Count; // reduce repeated allocations _tempValues = new object[count]; _tempTypes = new Type[count]; }
public FreeTextComboBoxControl() { InitializeComponent(); var binding = new Binding(); binding.Source = this; binding.Path = new PropertyPath("ValidatedText"); var validator = new MyValidationRule(this); binding.ValidationRules.Add(validator); binding.Mode = BindingMode.TwoWay; binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; _bindingExpression = _cbChoice.SetBinding(ComboBox.TextProperty, binding); }
public MenuCheckBox(UIElement inputBindingOwner, Codon codon, object caller, IEnumerable<ICondition> conditions) : base(codon, caller, conditions) { this.Command = CommandWrapper.GetCommand(codon, caller, true, conditions); CommandWrapper wrapper = this.Command as CommandWrapper; if (wrapper != null) { ICheckableMenuCommand cmd = wrapper.GetAddInCommand() as ICheckableMenuCommand; if (cmd != null) { isCheckedBinding = SetBinding(IsCheckedProperty, new Binding("IsChecked") { Source = cmd, Mode = BindingMode.OneWay }); } } if (!string.IsNullOrEmpty(codon.Properties["shortcut"])) { KeyGesture kg = MenuService.ParseShortcut(codon.Properties["shortcut"]); MenuCommand.AddGestureToInputBindingOwner(inputBindingOwner, kg, this.Command, null); this.InputGestureText = kg.GetDisplayStringForCulture(Thread.CurrentThread.CurrentUICulture); } }
protected DelayBinding(BindingExpressionBase binding_expression, DependencyObject binding_target, DependencyProperty binding_target_property, TimeSpan delay) { this.binding_expression = binding_expression; // Subscribe to notifications for when the target property changes. This event handler will be // invoked when the user types, clicks, or anything else which changes the target property var descriptor = DependencyPropertyDescriptor.FromProperty(binding_target_property, binding_target.GetType()); descriptor.AddValueChanged(binding_target, BindingTargetTargetPropertyChanged); // Add support so that the Enter key causes an immediate commit var frameworkElement = binding_target as FrameworkElement; if (frameworkElement != null) { frameworkElement.KeyUp += BindingTargetKeyUp; } // Setup the timer, but it won't be started until changes are detected timer = new DispatcherTimer(); timer.Tick += TimerTick; timer.Interval = delay; }
public ToolBarCheckBox(Codon codon, object caller, IReadOnlyCollection<ICondition> conditions) { ToolTipService.SetShowOnDisabled(this, true); this.codon = codon; this.caller = caller; this.conditions = conditions; this.Command = CommandWrapper.CreateCommand(codon, conditions); this.CommandParameter = caller; ICheckableMenuCommand cmd = CommandWrapper.Unwrap(this.Command) as ICheckableMenuCommand; if (cmd != null) { isCheckedBinding = SetBinding(IsCheckedProperty, new Binding("IsChecked") { Source = cmd, Mode = BindingMode.OneWay }); } this.Content = ToolBarService.CreateToolBarItemContent(codon); if (codon.Properties.Contains("name")) { this.Name = codon.Properties["name"]; } UpdateText(); SetResourceReference(FrameworkElement.StyleProperty, ToolBar.CheckBoxStyleKey); }
protected DelayBinding(BindingExpressionBase bindingExpression, DependencyObject bindingTarget, DependencyProperty bindingTargetProperty, TimeSpan delay) { _bindingExpression = bindingExpression; _delay = delay; // Subscribe to notifications for when the target property changes. This event handler will be // invoked when the user types, clicks, or anything else which changes the target property _descriptor = DependencyPropertyDescriptor.FromProperty(bindingTargetProperty, bindingTarget.GetType()); // Add support so that the Enter key causes an immediate commit bindingTarget.SaftyInvoke<FrameworkElement>(el => { el.Loaded += OnBindingTargetLoaded; }); // Setup the timer, but it won't be started until changes are detected _timer = new DispatcherTimer(); _timer.Tick += TimerTick; _timer.Interval = _delay; }
void EnsureView(object source, Type collectionViewType) { if (_isInitializing || _deferLevel > 0) { return; } DataSourceProvider dataProvider = source as DataSourceProvider; // listen for DataChanged events from an DataSourceProvider if (dataProvider != _dataProvider) { if (_dataProvider != null) { DataChangedEventManager.RemoveHandler(_dataProvider, OnDataChanged); } _dataProvider = dataProvider; if (_dataProvider != null) { DataChangedEventManager.AddHandler(_dataProvider, OnDataChanged); _dataProvider.InitialLoad(); } } // if the source is DataSourceProvider, use its Data instead if (dataProvider != null) { source = dataProvider.Data; } // get the view ICollectionView view = null; if (source != null) { DataBindEngine engine = DataBindEngine.CurrentDataBindEngine; ViewRecord viewRecord = engine.GetViewRecord(source, this, collectionViewType, true, (object x) => { BindingExpressionBase beb = BindingOperations.GetBindingExpressionBase(this, SourceProperty); return((beb != null) ? beb.GetSourceItem(x) : null); }); if (viewRecord != null) { view = viewRecord.View; _isViewInitialized = viewRecord.IsInitialized; // bring view up to date with the CollectionViewSource if (_version != viewRecord.Version) { ApplyPropertiesToView(view); viewRecord.Version = _version; } } } // update the View property SetValue(ViewPropertyKey, view); }
/// <summary> /// Create an appropriate expression for this Binding, to be attached /// to the given DependencyProperty on the given DependencyObject. /// </summary> internal BindingExpressionBase CreateBindingExpression(DependencyObject targetObject, DependencyProperty targetProperty, BindingExpressionBase owner) { _isSealed = true; return CreateBindingExpressionOverride(targetObject, targetProperty, owner); }
private static void NavigateBindingExpressionTree( BindingExpressionBase bindingExpressionBase, Action<BindingExpression> action) { BindingExpression bindingExpression = bindingExpressionBase as BindingExpression; if (bindingExpression != null) { action(bindingExpression); return; } MultiBindingExpression multiBindingExpression = bindingExpressionBase as MultiBindingExpression; if (multiBindingExpression != null) { foreach (var subExpression in multiBindingExpression.BindingExpressions) { NavigateBindingExpressionTree(subExpression, action); } return; } PriorityBindingExpression priorityBindingExpression = bindingExpressionBase as PriorityBindingExpression; if (priorityBindingExpression != null) { foreach (var subExpression in priorityBindingExpression.BindingExpressions) { NavigateBindingExpressionTree(subExpression, action); } return; } throw new InvalidOperationException( string.Format( CultureInfo.CurrentCulture, Resources.ExceptionUnexpectedBindingExpression, bindingExpression.GetType().Name)); }
/// <summary> /// Clears the ValidationError that was set through a call /// to MarkInvalid or a previously failed validation of that BindingExpression. /// </summary> public static void ClearInvalid(BindingExpressionBase bindingExpression) { if (bindingExpression == null) throw new ArgumentNullException("bindingExpression"); bindingExpression.UpdateValidationError(null); }
//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ // Create a new BindingExpression from the given Binding description internal static PriorityBindingExpression CreateBindingExpression(DependencyObject d, DependencyProperty dp, PriorityBinding binding, BindingExpressionBase owner) { FrameworkPropertyMetadata fwMetaData = dp.GetMetadata(d.DependencyObjectType) as FrameworkPropertyMetadata; if ((fwMetaData != null && !fwMetaData.IsDataBindingAllowed) || dp.ReadOnly) { throw new ArgumentException(SR.Get(SRID.PropertyNotBindable, dp.Name), "dp"); } // create the BindingExpression PriorityBindingExpression bindExpr = new PriorityBindingExpression(binding, owner); return(bindExpr); }
/// <summary> /// Replace the given child expression with a new one. /// </summary> internal override void ReplaceChild(BindingExpressionBase bindingExpression) { // BindingExpression does not support child bindings }
//------------------------------------------------------ // // Protected Methods // //------------------------------------------------------ /// <summary> /// Invalidate the given child expression. /// </summary> internal override void InvalidateChild(BindingExpressionBase bindingExpression) { // BindingExpression does not support child bindings }
// Token: 0x06001C7B RID: 7291 RVA: 0x00085F2C File Offset: 0x0008412C internal override bool ObtainConvertedProposedValue(BindingGroup bindingGroup) { BindingExpressionBase activeBindingExpression = this.ActiveBindingExpression; return(activeBindingExpression == null || activeBindingExpression.ObtainConvertedProposedValue(bindingGroup)); }
// Token: 0x06001C80 RID: 7296 RVA: 0x00085FFC File Offset: 0x000841FC internal override bool CheckValidationRules(BindingGroup bindingGroup, ValidationStep validationStep) { BindingExpressionBase activeBindingExpression = this.ActiveBindingExpression; return(activeBindingExpression == null || activeBindingExpression.CheckValidationRules(bindingGroup, validationStep)); }
// Token: 0x06001C7F RID: 7295 RVA: 0x00085FD8 File Offset: 0x000841D8 internal override bool Validate(object value, ValidationStep validationStep) { BindingExpressionBase activeBindingExpression = this.ActiveBindingExpression; return(activeBindingExpression == null || activeBindingExpression.Validate(value, validationStep)); }
/// <summary> /// Retrieve a BindingBase. /// </summary> /// <remarks> /// This method returns null if no Binding has been set on the given /// property. /// </remarks> /// <param name="target">object from which to retrieve the binding</param> /// <param name="dp">property from which to retrieve the binding</param> /// <exception cref="ArgumentNullException"> target and dp cannot be null </exception> public static BindingBase GetBindingBase(DependencyObject target, DependencyProperty dp) { BindingExpressionBase b = GetBindingExpressionBase(target, dp); return((b != null) ? b.ParentBindingBase : null); }
/// <summary> /// Create an appropriate expression for this Binding, to be attached /// to the given DependencyProperty on the given DependencyObject. /// </summary> internal BindingExpressionBase CreateBindingExpression(DependencyObject targetObject, DependencyProperty targetProperty, BindingExpressionBase owner) { _isSealed = true; return(CreateBindingExpressionOverride(targetObject, targetProperty, owner)); }
//------------------------------------------------------ // // Protected Methods // //------------------------------------------------------ /// <summary> /// Create an appropriate expression for this Binding, to be attached /// to the given DependencyProperty on the given DependencyObject. /// </summary> internal abstract BindingExpressionBase CreateBindingExpressionOverride(DependencyObject targetObject, DependencyProperty targetProperty, BindingExpressionBase owner);
public static TestValidationError GetFor(BindingExpressionBase expression) { return new TestValidationError(expression); }
// Token: 0x06001C78 RID: 7288 RVA: 0x00085EC4 File Offset: 0x000840C4 internal override bool ShouldReactToDirtyOverride() { BindingExpressionBase activeBindingExpression = this.ActiveBindingExpression; return(activeBindingExpression != null && activeBindingExpression.ShouldReactToDirtyOverride()); }
// Token: 0x06001C70 RID: 7280 RVA: 0x00085BF8 File Offset: 0x00083DF8 internal static PriorityBindingExpression CreateBindingExpression(DependencyObject d, DependencyProperty dp, PriorityBinding binding, BindingExpressionBase owner) { FrameworkPropertyMetadata frameworkPropertyMetadata = dp.GetMetadata(d.DependencyObjectType) as FrameworkPropertyMetadata; if ((frameworkPropertyMetadata != null && !frameworkPropertyMetadata.IsDataBindingAllowed) || dp.ReadOnly) { throw new ArgumentException(SR.Get("PropertyNotBindable", new object[] { dp.Name }), "dp"); } return(new PriorityBindingExpression(binding, owner)); }
internal static void InitializeTracing(BindingExpressionBase expr, DependencyObject d, DependencyProperty dp) { BindingBase parent = expr.ParentBindingBase; }
/// <summary> /// Change the dependency sources for the given child expression. /// </summary> internal override void ChangeSourcesForChild(BindingExpressionBase bindingExpression, WeakDependencySource[] newSources) { // BindingExpression does not support child bindings }
/// <summary> /// Invalidate the given child expression. /// </summary> internal abstract void InvalidateChild(BindingExpressionBase bindingExpression);
//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ // Create a new BindingExpression from the given Bind description internal static BindingExpression CreateBindingExpression(DependencyObject d, DependencyProperty dp, Binding binding, BindingExpressionBase parent) { FrameworkPropertyMetadata fwMetaData = dp.GetMetadata(d.DependencyObjectType) as FrameworkPropertyMetadata; if ((fwMetaData != null && !fwMetaData.IsDataBindingAllowed) || dp.ReadOnly) throw new ArgumentException(SR.Get(SRID.PropertyNotBindable, dp.Name), "dp"); // create the BindingExpression BindingExpression bindExpr = new BindingExpression(binding, parent); bindExpr.ResolvePropertyDefaultSettings(binding.Mode, binding.UpdateSourceTrigger, fwMetaData); // Two-way Binding with an empty path makes no sense if (bindExpr.IsReflective && binding.XPath == null && (binding.Path == null || String.IsNullOrEmpty(binding.Path.Path))) throw new InvalidOperationException(SR.Get(SRID.TwoWayBindingNeedsPath)); return bindExpr; }
/// <summary> /// Change the dependency sources for the given child expression. /// </summary> internal abstract void ChangeSourcesForChild(BindingExpressionBase bindingExpression, WeakDependencySource[] newSources);
/// <summary> /// Mark this BindingExpression as invalid. If the BindingExpression has been /// explicitly marked invalid in this way, then it will remain /// invalid until ClearInvalid is called or another transfer to the source validates successfully. /// </summary> public static void MarkInvalid(BindingExpressionBase bindingExpression, ValidationError validationError) { if (bindingExpression == null) throw new ArgumentNullException("bindingExpression"); if (validationError == null) throw new ArgumentNullException("validationError"); bindingExpression.UpdateValidationError(validationError); }
/// <summary> /// Replace the given child expression with a new one. /// </summary> internal abstract void ReplaceChild(BindingExpressionBase bindingExpression);
//----------------------------------------------------- // // Protected Methods // //------------------------------------------------------ /// <summary> /// Create an appropriate expression for this Binding, to be attached /// to the given DependencyProperty on the given DependencyObject. /// </summary> internal override BindingExpressionBase CreateBindingExpressionOverride(DependencyObject target, DependencyProperty dp, BindingExpressionBase owner) { return BindingExpression.CreateBindingExpression(target, dp, this, owner); }
// Token: 0x06001C68 RID: 7272 RVA: 0x00085AFB File Offset: 0x00083CFB private PriorityBindingExpression(PriorityBinding binding, BindingExpressionBase owner) : base(binding, owner) { }
//------------------------------------------------------ // // Protected Methods // //------------------------------------------------------ /// <summary> /// Create an appropriate expression for this Binding, to be attached /// to the given DependencyProperty on the given DependencyObject. /// </summary> internal abstract BindingExpressionBase CreateBindingExpressionOverride(DependencyObject targetObject, DependencyProperty targetProperty, BindingExpressionBase owner);
private TestValidationError(BindingExpressionBase bindingInError) : base(TestValidationRule.Default, bindingInError) { }
//----------------------------------------------------- // // Constructors // //----------------------------------------------------- /// <summary> Constructor </summary> internal BindingExpressionBase(BindingBase binding, BindingExpressionBase parent) : base(ExpressionMode.SupportsUnboundSources) { if (binding == null) throw new ArgumentNullException("binding"); _binding = binding; _parentBindingExpression = parent; _flags = (PrivateFlags)binding.Flags; if (parent != null) { ResolveNamesInTemplate = parent.ResolveNamesInTemplate; Type type = parent.GetType(); if (type == typeof(MultiBindingExpression)) ChangeFlag(PrivateFlags.iInMultiBindingExpression, true); else if (type == typeof(PriorityBindingExpression)) ChangeFlag(PrivateFlags.iInPriorityBindingExpression, true); } // initialize tracing information PresentationTraceLevel traceLevel = PresentationTraceSources.GetTraceLevel(binding); if (traceLevel > 0) { // copy TraceLevel from parent BindingBase - it can be changed later PresentationTraceSources.SetTraceLevel(this, traceLevel); } if (TraceData.IsExtendedTraceEnabled(this, TraceDataLevel.CreateExpression)) { if (parent == null) { TraceData.Trace(TraceEventType.Warning, TraceData.CreatedExpression( TraceData.Identify(this), TraceData.Identify(binding))); } else { TraceData.Trace(TraceEventType.Warning, TraceData.CreatedExpressionInParent( TraceData.Identify(this), TraceData.Identify(binding), TraceData.Identify(parent))); } } if (LookupValidationRule(typeof(ExceptionValidationRule)) != null) { ChangeFlag(PrivateFlags.iValidatesOnExceptions, true); } if (LookupValidationRule(typeof(DataErrorValidationRule)) != null) { ChangeFlag(PrivateFlags.iValidatesOnDataErrors, true); } }
//------------------------------------------------------ // // Protected Methods // //------------------------------------------------------ /// <summary> /// Create an appropriate expression for this Binding, to be attached /// to the given DependencyProperty on the given DependencyObject. /// </summary> internal override BindingExpressionBase CreateBindingExpressionOverride(DependencyObject target, DependencyProperty dp, BindingExpressionBase owner) { return(PriorityBindingExpression.CreateBindingExpression(target, dp, this, owner)); }