Example #1
0
        private Inline ImageInlineEvaluator(Match match)
        {
            if (match == null)
            {
                throw new ArgumentNullException("match");
            }

            string      linkText  = match.Groups[2].Value;
            string      url       = match.Groups[3].Value;
            BitmapImage imgSource = null;
            Image       image     = null;

            try {
                string assembly_name = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
                //url = url.Replace('/', '\\');
                string resource_url = $"pack://application:,,,/" + url;  // https://stackoverflow.com/questions/12954327/dynamically-adding-and-loading-image-from-resources-in-c-sharp
                Uri    resource_uri = new Uri(resource_url);

                // Загрузить изображение надо в любом случае т.к. надо узнать его ширину ниже.
                BitmapImage bi = new BitmapImage();
                bi.BeginInit();
                bi.UriSource = resource_uri;
                bi.EndInit();
                imgSource = bi;

                //Binding b = new Binding("ActualWidth");

                // Анимированные gif-ки надо подгружать немного иначе через компонент XamlAnimatedGif:
                if (System.IO.Path.GetExtension(url).ToLower().Equals(".gif") == true)
                {
                    image = new Image()
                    {
                        Stretch = Stretch.UniformToFill                                         /*, MaxWidth=500*/
                    };
                    XamlAnimatedGif.AnimationBehavior.SetSourceUri(image, imgSource.UriSource); // https://wpfanimatedgif.codeplex.com/documentation
                }
                else
                {
                    image = new Image {
                        Source = imgSource, Tag = linkText, Stretch = Stretch.UniformToFill               /*, MaxWidth = 500*/
                    };
                }

                //if (!Uri.IsWellFormedUriString(url, UriKind.Absolute) && !System.IO.Path.IsPathRooted(url)) {
                //    url = System.IO.Path.Combine(AssetPathRoot ?? string.Empty, url);
                //}

                //imgSource = new BitmapImage(new Uri(url, UriKind.RelativeOrAbsolute));
            }
            catch (Exception) {
                return(new Run("!" + url)
                {
                    Foreground = Brushes.Red
                });
            }

            if (ImageStyle == null)
            {
                image.Margin = new Thickness(0);
            }
            else
            {
                image.Style = ImageStyle;
            }

            // Bind size so document is updated when image is downloaded
            if (imgSource.IsDownloading)
            {
                Binding binding = new Binding(nameof(BitmapImage.Width));
                binding.Source = imgSource;
                binding.Mode   = BindingMode.OneWay;

                BindingExpressionBase bindingExpression        = BindingOperations.SetBinding(image, Image.WidthProperty, binding);
                EventHandler          downloadCompletedHandler = null;
                downloadCompletedHandler = (sender, e) =>
                {
                    imgSource.DownloadCompleted -= downloadCompletedHandler;
                    bindingExpression.UpdateTarget();
                };
                imgSource.DownloadCompleted += downloadCompletedHandler;
            }
            else
            {
                //image.Width = imgSource.Width;
                //image.SnapsToDevicePixels = true;
                image.Width = imgSource.PixelWidth;
            }
            InlineUIContainer iuc = new InlineUIContainer(image);

            return(iuc);
        }
Example #2
0
        public virtual ValidationResult Validate(object value, CultureInfo cultureInfo, BindingExpressionBase owner)
        {
            switch (_validationStep)
            {
            case ValidationStep.UpdatedValue:
            case ValidationStep.CommittedValue:
                value = owner;
                break;
            }

            return(Validate(value, cultureInfo));
        }
 public static TestValidationError GetFor(BindingExpressionBase expression)
 {
     return(new TestValidationError(expression));
 }
 public override ValidationResult Validate(object value, CultureInfo cultureInfo, BindingExpressionBase owner)
 {
     Parameters?.SetBindingExpression(owner);
     return(base.Validate(value, cultureInfo, owner));
 }
Example #5
0
        // return true if the dp is bound via the given Binding
        bool IsBound(DependencyProperty dp, Binding binding)
        {
            BindingExpressionBase bindExpr = BindingOperations.GetBindingExpression(this, dp);

            return(bindExpr != null && bindExpr.ParentBindingBase == binding);
        }
Example #6
0
            /// <summary>
            /// DragEnd event handler from DragDrop behavior.
            /// </summary>
            private void SourceDoDragDrop(ITextSelection selection, IDataObject dataObject)
            {
                // Run OLE drag-drop process. It will eat all user input until the drop
                DragDropEffects allowedDragDropEffects = DragDropEffects.Copy;

                if (!_textEditor.IsReadOnly)
                {
                    allowedDragDropEffects |= DragDropEffects.Move;
                }

                DragDropEffects resultingDragDropEffects = DragDropEffects.None;

                try
                {
                    resultingDragDropEffects = DragDrop.DoDragDrop( //
                        _textEditor.UiScope,                        // dragSource,
                        dataObject,                                 //
                        allowedDragDropEffects);
                }
                // Ole32's DoDragDrop can return E_UNEXCEPTED, which comes to us as a COMException,
                // if something unexpected happened during the drag and drop operation,
                // e.g. the application receiving the drop failed. In this case we should
                // not fail, we should catch the exception and act as if the drop wasn't allowed.
                catch (COMException ex) when(ex.HResult == NativeMethods.E_UNEXPECTED)
                {
                }

                // Remove source selection
                if (!_textEditor.IsReadOnly &&                          //
                    resultingDragDropEffects == DragDropEffects.Move && //
                    _dragSourceTextRange != null &&
                    !_dragSourceTextRange.IsEmpty)
                {
                    // Normally we delete the source selection from OnDrop event,
                    // unless source and target TextBoxes are different.
                    // In this case the source selection is still not empty,
                    // which means that target was in a different TextBox.
                    // So we still need to delete the selected content in the source one.
                    // This will create an undo unit different from a dropping one,
                    // which is ok, because it will be in different TextBox's undo stack.
                    using (selection.DeclareChangeBlock())
                    {
                        // This is end of Move - we need to delete source content
                        _dragSourceTextRange.Text = String.Empty;
                    }
                }

                // Clean up the text range.
                _dragSourceTextRange = null;

                // Check the data binding expression and update the source and target if the drag source
                // has the binding expression. Without this, data binding is broken after complete the
                // drag-drop operation because Drop() paste the object then set the focus to the target.
                // The losting focus invoke the data binding expression's Update(), but the source isn't
                // updated yet before complete DoDragDrop.
                if (!_textEditor.IsReadOnly)
                {
                    BindingExpressionBase bindingExpression = BindingOperations.GetBindingExpressionBase(
                        _textEditor.UiScope, TextBox.TextProperty);
                    if (bindingExpression != null)
                    {
                        bindingExpression.UpdateSource();
                        bindingExpression.UpdateTarget();
                    }
                }
            }
 public void SetBinding(BindingExpressionBase bindingExpression)
 {
     BindingExpression = bindingExpression;
 }
Example #8
0
 public virtual void BindingCreated(BindingExpressionBase expression, string resource)
 {
 }
Example #9
0
        internal void SetValueImpl(DependencyProperty dp, object value)
        {
            if (value == DependencyProperty.UnsetValue)
            {
                ClearValue(dp);
                return;
            }

            bool                  updateTwoWay      = false;
            bool                  addingExpression  = false;
            Expression            existing          = null;
            Expression            expression        = value as Expression;
            BindingExpressionBase bindingExpression = expression as BindingExpressionBase;

            if (bindingExpression != null)
            {
                string path = bindingExpression.Binding.Path.Path;
                if ((string.IsNullOrEmpty(path) || path == ".") &&
                    bindingExpression.Binding.Mode == BindingMode.TwoWay)
                {
                    throw new ArgumentException("TwoWay bindings require a non-empty Path");
                }
                bindingExpression.Binding.Seal();
            }

            if (expressions != null)
            {
                if (!expressions.TryGetValue(dp, out existing))
                {
                    existing = null;
                }
            }

            if (expression != null)
            {
                if (existing != expression)
                {
                    if (expression.Attached)
                    {
                        throw new ArgumentException("Cannot attach the same Expression to multiple FrameworkElements");
                    }

                    if (existing != null)
                    {
                        RemoveExpression(dp);
                    }
                    if (expressions == null)
                    {
                        expressions = new Dictionary <DependencyProperty, Expression> ();
                    }

                    expressions.Add(dp, expression);
                    expression.OnAttached(this);
                }
                addingExpression = true;
                value            = expression.GetValue(dp);
            }
            else if (existing != null)
            {
                if (existing is BindingExpressionBase)
                {
                    BindingExpressionBase beb = (BindingExpressionBase)existing;

                    if (beb.Binding.Mode == BindingMode.TwoWay)
                    {
                        updateTwoWay = !beb.Updating && !(dp is CustomDependencyProperty);
                    }
                    else if (!beb.Updating || beb.Binding.Mode == BindingMode.OneTime)
                    {
                        RemoveExpression(dp);
                    }
                }
                else if (!existing.Updating)
                {
                    RemoveExpression(dp);
                }
            }

            try {
                NativeDependencyObjectHelper.SetValue(this, dp, value);
                if (updateTwoWay)
                {
                    ((BindingExpressionBase)existing).TryUpdateSourceObject(value);
                }
            } catch {
                if (!addingExpression)
                {
                    throw;
                }
                else
                {
                    NativeDependencyObjectHelper.SetValue(this, dp, dp.GetDefaultValue(this));
                    if (updateTwoWay)
                    {
                        ((BindingExpressionBase)existing).TryUpdateSourceObject(value);
                    }
                }
            }
        }
        /// <summary>Performs validation checks on a value.</summary>
        /// <param name="value">The value from the binding target to check.</param>
        /// <param name="cultureInfo">The culture to use in this rule.</param>
        /// <param name="owner">The binding expression that uses the validation rule.</param>
        /// <returns>A <see cref="T:System.Windows.Controls.ValidationResult" /> object.</returns>
        // Token: 0x0600599F RID: 22943 RVA: 0x0018B870 File Offset: 0x00189A70
        public virtual ValidationResult Validate(object value, CultureInfo cultureInfo, BindingExpressionBase owner)
        {
            ValidationStep validationStep = this._validationStep;

            if (validationStep - ValidationStep.UpdatedValue <= 1)
            {
                value = owner;
            }
            return(this.Validate(value, cultureInfo));
        }
Example #11
0
 /// <summary>
 /// Validate a value against a collection of validation rules.
 /// </summary>
 /// <param name="value">The value to validate.</param>
 /// <param name="validationRules">The validation rules collection.</param>
 /// <param name="bindingExpression">The binding expression.</param>
 private static void Validate(object value, IEnumerable <ValidationRule>?validationRules, BindingExpressionBase bindingExpression)
 {
     if (validationRules != null)
     {
         foreach (ValidationRule rule in validationRules)
         {
             ValidationResult result = rule.Validate(value, CultureInfo.InvariantCulture);
             if (!result.IsValid)
             {
                 Validation.MarkInvalid(bindingExpression, new ValidationError(rule, bindingExpression.ParentBindingBase, result.ErrorContent, null));
                 return;
             }
         }
     }
     Validation.ClearInvalid(bindingExpression);
 }
Example #12
0
        public override ValidationResult Validate(object value, CultureInfo cultureInfo, BindingExpressionBase owner)
        {
            TabExpTabAsientoVM VM    = (TabExpTabAsientoVM)((BindingExpression)owner).DataItem;
            string             input = (string)value;

            if (!VM.Asiento.Abierto)
            {
                return(new ValidationResult(false, GlobalSettings.Properties.ContabilidadSettings.Default.MENSAJESERROR_ASIENTO_ASIENTOCERRADO));
            }

            decimal importe;

            if (!decimal.TryParse(input, out importe))
            {
                if (!VM.AsientoComplejoSiHayMasDeDosApuntes())
                {
                    return(new ValidationResult(false, GlobalSettings.Properties.ContabilidadSettings.Default.MENSAJESERROR_ASIENTO_LETRASENCELDAIMPORTE));
                }

                return(new ValidationResult(true, null));
            }

            return(new ValidationResult(true, null));
        }
Example #13
0
        public override wc.ValidationResult Validate(object value, CultureInfo cultureInfo, BindingExpressionBase owner)
        {
            var    mBind    = (BindingExpression)owner;
            object ds       = mBind.DataItem;
            var    propName = mBind.ParentBinding.Path.Path;

            TypeDescriptor.AddProviderTransparent(new dn.AssociatedMetadataTypeTypeDescriptionProvider(ds.GetType()), ds.GetType());

            _Fehler = new List <dn.ValidationResult>();
            var validationContext = new dn.ValidationContext(ds)
            {
                MemberName = propName
            };
            var bo = dn.Validator.TryValidateProperty(value, validationContext, _Fehler);

            return(base.Validate(value, cultureInfo, owner));
        }
Example #14
0
 internal void AddBinding(BindingExpressionBase binding)
 {
     _bindings.Add(binding);
 }
Example #15
0
        private void Update()
        {
            if (ignoreUpdate)
            {
                return;
            }

            this.isLocallySet     = false;
            this.isInvalidBinding = false;
            this.isDatabound      = false;

            DependencyProperty dp = this.DependencyProperty;
            DependencyObject   d  = target as DependencyObject;

            if (SnoopModes.MultipleDispatcherMode && d != null && d.Dispatcher != this.Dispatcher)
            {
                return;
            }

            if (dp != null && d != null)
            {
                if (d.ReadLocalValue(dp) != DependencyProperty.UnsetValue)
                {
                    this.isLocallySet = true;
                }

                BindingExpressionBase expression = BindingOperations.GetBindingExpressionBase(d, dp);
                if (expression != null)
                {
                    this.isDatabound = true;

                    if (expression.HasError || expression.Status != BindingStatus.Active)
                    {
                        this.isInvalidBinding = true;

                        StringBuilder           builder = new StringBuilder();
                        StringWriter            writer  = new StringWriter(builder);
                        TextWriterTraceListener tracer  = new TextWriterTraceListener(writer);
                        PresentationTraceSources.DataBindingSource.Listeners.Add(tracer);

                        // reset binding to get the error message.
                        ignoreUpdate = true;
                        d.ClearValue(dp);
                        BindingOperations.SetBinding(d, dp, expression.ParentBindingBase);
                        ignoreUpdate = false;

                        // this needs to happen on idle so that we can actually run the binding, which may occur asynchronously.
                        Dispatcher.BeginInvoke
                        (
                            DispatcherPriority.ApplicationIdle,
                            new DispatcherOperationCallback
                            (
                                delegate(object source)
                        {
                            bindingError = builder.ToString();
                            this.OnPropertyChanged("BindingError");
                            PresentationTraceSources.DataBindingSource.Listeners.Remove(tracer);
                            writer.Close();
                            return(null);
                        }
                            ),
                            null
                        );
                    }
                    else
                    {
                        bindingError = string.Empty;
                    }
                }

                this.valueSource = DependencyPropertyHelper.GetValueSource(d, dp);
            }

            this.OnPropertyChanged("IsLocallySet");
            this.OnPropertyChanged("IsInvalidBinding");
            this.OnPropertyChanged("StringValue");
            this.OnPropertyChanged("DescriptiveValue");
            this.OnPropertyChanged("IsDatabound");
            this.OnPropertyChanged("IsExpression");
            this.OnPropertyChanged("IsAnimated");
            this.OnPropertyChanged("ValueSource");
        }
Example #16
0
 internal void RemoveBinding(BindingExpressionBase binding)
 {
     _bindings.Remove(binding);
 }
Example #17
0
        public override ValidationResult Validate(object value, CultureInfo cultureInfo, BindingExpressionBase owner)
        {
            var s       = value as string;
            var textBox = (TextBox)owner.Target;

            return(Validate(s, textBox));
        }
Example #18
0
        /// <summary>
        /// See <see cref="AnalyzerBase.Analyze" />
        /// </summary>
        public override void Analyze(TreeItem treeItem, AnalyzerContext analyzerContext)
        {
            PresentationTraceSources.SetTraceLevel(treeItem.Instance, PresentationTraceLevel.High);
            var dependencyObject = treeItem.Instance as DependencyObject;

            if (dependencyObject == null)
            {
                return;
            }

            if (_pendingTreeItems.ContainsKey(treeItem))
            {
                return;
            }

            var backgroundHelper = new DataBindingBackgroundHelper(this, treeItem, analyzerContext, () => _pendingTreeItems.Remove(treeItem));

            _pendingTreeItems.Add(treeItem, backgroundHelper);

            foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(dependencyObject.GetType()))
            {
                var dpd = DependencyPropertyDescriptor.FromProperty(property);
                if (dpd != null)
                {
                    BindingExpressionBase binding = BindingOperations.GetBindingExpressionBase(dependencyObject, dpd.DependencyProperty);
                    if (binding != null)
                    {
                        if (binding.HasError || binding.Status != BindingStatus.Active)
                        {
                            var callback = backgroundHelper.CreateCallback();

                            // Ensure that no pending calls are in the dispatcher queue
                            Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.SystemIdle, (Action) delegate
                            {
                                var stringBuilder = new StringBuilder();
                                var stringWriter  = new StringWriter(stringBuilder);
                                var listener      = new TextWriterTraceListener(stringWriter);
                                PresentationTraceSources.DataBindingSource.Listeners.Add(listener);
                                PresentationTraceSources.SetTraceLevel(treeItem.Instance, PresentationTraceLevel.High);

                                // Remove and add the binding to re-trigger the binding error
                                dependencyObject.ClearValue(dpd.DependencyProperty);
                                BindingOperations.SetBinding(dependencyObject, dpd.DependencyProperty, binding.ParentBindingBase);

                                listener.Flush();
                                stringWriter.Flush();

                                Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.SystemIdle, (Action) delegate
                                {
                                    string bindingError = stringBuilder.ToString();
                                    if (bindingError.Length > 0)
                                    {
                                        int prefix   = bindingError.IndexOf(':');
                                        bindingError = bindingError.Substring(prefix + 6).Replace("\r", "").Replace("\n", "");

                                        callback.Issue = new Issue("BindingError", string.Format("{0}: {1}", dpd.DisplayName, bindingError),
                                                                   IssueSeverity.Error, IssueCategory.Functionality,
                                                                   treeItem, dpd);
                                    }
                                    PresentationTraceSources.DataBindingSource.Listeners.Remove(listener);
                                    listener.Close();

                                    callback.SetDone();
                                });
                            });
                        }
                    }
                }
            }

            backgroundHelper.ReportIssues();
        }
        /// <inheritdoc/>
        public override ValidationResult Validate(object value, CultureInfo cultureInfo, BindingExpressionBase owner)
        {
            var box = (BaseBox)((BindingExpression)owner).Target;

            if (box.TextSource == TextSource.None)
            {
                return(ValidationResult.ValidResult);
            }

            var text    = (string)value;
            var pattern = box.RegexPattern;

            if (string.IsNullOrEmpty(pattern))
            {
                return(ValidationResult.ValidResult);
            }

            if (string.IsNullOrEmpty(text))
            {
                return(RegexValidationResult.CreateErrorResult(text, box));
            }

            try
            {
                if (Regex.IsMatch(text, pattern))
                {
                    return(ValidationResult.ValidResult);
                }

                return(RegexValidationResult.CreateErrorResult(text, box));
            }
            catch (Exception e)
            {
                return(RegexValidationResult.CreateMalformedPatternErrorResult(text, e, box));
            }
        }
Example #20
0
        public override ValidationResult Validate(object value, CultureInfo cultureInfo, BindingExpressionBase owner)
        {
            string name       = (string)value;
            var    expression = owner as BindingExpression;

            if (expression.ResolvedSource is PObject pObj)
            {
                var renderer = pObj.GetRenderer();

                if (renderer != null)
                {
                    var scope = LogicalTreeHelperEx.FindLogicalParents <INameScope>(renderer.Element).FirstOrDefault();

                    if (pObj.Equals(scope.GetOwner(name)))
                    {
                        return(base.Validate(true, cultureInfo, owner));
                    }

                    if (string.IsNullOrEmpty(name))
                    {
                        scope.Unregister(pObj);

                        return(base.Validate(true, cultureInfo, owner));
                    }

                    if (Core.StringRule.IsValidName(name ?? "", true))
                    {
                        if (scope.HasName(name))
                        {
                            MessageBox.Show($"'{name}'는 이미 정의된 이름입니다.", "DeXign", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                            expression.UpdateTarget();
                        }
                        else
                        {
                            scope.Register(pObj, name);

                            return(base.Validate(true, cultureInfo, owner));
                        }
                    }
                }
                else
                {
                    MessageBox.Show($"네임 스코프를 찾을 수 없습니다.", "DeXign");
                }
            }

            return(base.Validate(false, cultureInfo, owner));
        }
Example #21
0
 internal WeakDependencySource(DependencyObject item, DependencyProperty dp)
 {
     _item = BindingExpressionBase.CreateReference(item);
     _dp   = dp;
 }
 private TestValidationError(BindingExpressionBase bindingInError)
     : base(TestValidationRule.Default, bindingInError)
 {
 }
 protected void AddBinding(BindingExpressionBase bindingExpression)
 {
     _bindingExpressions.Add(bindingExpression);
 }
 internal void SetBindingExpression(BindingExpressionBase binding)
 {
     m_Binding = binding;
 }
Example #25
0
        private Inline ImageInlineEvaluator(Match match)
        {
            if (match is null)
            {
                throw new ArgumentNullException(nameof(match));
            }

            string      linkText  = match.Groups[2].Value;
            string      url       = match.Groups[3].Value;
            BitmapImage imgSource = null;

            try
            {
                if (!Uri.IsWellFormedUriString(url, UriKind.Absolute) && !System.IO.Path.IsPathRooted(url))
                {
                    url = System.IO.Path.Combine(AssetPathRoot ?? string.Empty, url);
                }

                imgSource = new BitmapImage();
                imgSource.BeginInit();
                imgSource.CacheOption    = BitmapCacheOption.None;
                imgSource.UriCachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache);
                imgSource.CacheOption    = BitmapCacheOption.OnLoad;
                imgSource.CreateOptions  = BitmapCreateOptions.IgnoreImageCache;
                imgSource.UriSource      = new Uri(url);
                imgSource.EndInit();
            }
            catch (Exception)
            {
                return(new Run("!" + url)
                {
                    Foreground = Brushes.Red
                });
            }

            Image image = new Image {
                Source = imgSource, Tag = linkText
            };

            if (ImageStyle is null)
            {
                image.Margin = new Thickness(0);
            }
            else
            {
                image.Style = ImageStyle;
            }

            // Bind size so document is updated when image is downloaded
            if (imgSource.IsDownloading)
            {
                Binding binding = new Binding(nameof(BitmapImage.Width));
                binding.Source = imgSource;
                binding.Mode   = BindingMode.OneWay;

                BindingExpressionBase bindingExpression = BindingOperations.SetBinding(image, Image.WidthProperty, binding);

                void downloadCompletedHandler(object sender, EventArgs e)
                {
                    imgSource.DownloadCompleted -= downloadCompletedHandler;
                    bindingExpression.UpdateTarget();
                }

                imgSource.DownloadCompleted += downloadCompletedHandler;
            }
            else
            {
                image.Width = imgSource.Width;
            }

            return(new InlineUIContainer(image));
        }
Example #26
0
        private Inline ImageInlineEvaluator(Match match)
        {
            if (match == null)
            {
                throw new ArgumentNullException("match");
            }

            string      linkText  = match.Groups[2].Value;
            string      url       = match.Groups[3].Value;
            BitmapImage imgSource = null;

            try
            {
                if (!Uri.IsWellFormedUriString(url, UriKind.Absolute) && !System.IO.Path.IsPathRooted(url))
                {
                    url = System.IO.Path.Combine(AssetPathRoot ?? string.Empty, url);
                }

                imgSource = new BitmapImage(new Uri(url, UriKind.RelativeOrAbsolute));
            }
            catch (Exception)
            {
                return(new Run("!" + url)
                {
                    Foreground = Brushes.Red
                });
            }

            Image image = new Image {
                Source = imgSource, Tag = linkText
            };

            if (ImageStyle == null)
            {
                image.Margin = new Thickness(0);
            }
            else
            {
                image.Style = ImageStyle;
            }

            // Bind size so document is updated when image is downloaded
            if (imgSource.IsDownloading)
            {
                Binding binding = new Binding(nameof(BitmapImage.Width));
                binding.Source = imgSource;
                binding.Mode   = BindingMode.OneWay;

                BindingExpressionBase bindingExpression        = BindingOperations.SetBinding(image, Image.WidthProperty, binding);
                EventHandler          downloadCompletedHandler = null;
                downloadCompletedHandler = (sender, e) =>
                {
                    imgSource.DownloadCompleted -= downloadCompletedHandler;
                    bindingExpression.UpdateTarget();
                };
                imgSource.DownloadCompleted += downloadCompletedHandler;
            }
            else
            {
                image.Width = imgSource.Width;
            }

            return(new InlineUIContainer(image));
        }
Example #27
0
        public override ValidationResult Validate(object value, CultureInfo cultureInfo, BindingExpressionBase owner)
        {
            // Validate
            var result = base.Validate(value, cultureInfo, owner);

            // Update model
            if (owner is BindingExpression expression && expression.DataItem is ViewModels.FindProgram model)
            {
                model.IsFilenameValid = result.IsValid;
            }

            // Return
            return(result);
        }