public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            Guard.NotNull(() => provider, provider);

            this.provider = provider;

            var valueString = value as string;

            if (valueString != null)
            {
                var editorService = this.provider.GetService<IWindowsFormsEditorService>();

                if (editorService != null)
                {
                    this.SetContext(context);

                    using (var dialog = new ImageDialog(this, this.provider))
                    {
                        Uri @ref = null;

                        if (Uri.TryCreate(valueString, UriKind.Absolute, out @ref))
                        {
                            dialog.ImagePath = ResolveItemReference(@ref);
                        }
                        else
                        {
                            dialog.ImagePath = string.Empty;
                        }

                        if (editorService.ShowDialog(dialog) == DialogResult.OK)
                        {
                            valueString = dialog.ImagePath;

                            if (!string.IsNullOrEmpty(valueString))
                            {
                                value = valueString;
                            }
                        }
                    }
                }
            }

            return CreateItemReference(value);
        }
Exemple #2
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            Guard.NotNull(() => provider, provider);

            this.provider = provider;

            var valueString = value as string;

            if (valueString != null)
            {
                var editorService = this.provider.GetService <IWindowsFormsEditorService>();

                if (editorService != null)
                {
                    this.SetContext(context);

                    using (var dialog = new ImageDialog(this, this.provider))
                    {
                        Uri @ref = null;

                        if (Uri.TryCreate(valueString, UriKind.Absolute, out @ref))
                        {
                            dialog.ImagePath = ResolveItemReference(@ref);
                        }
                        else
                        {
                            dialog.ImagePath = string.Empty;
                        }

                        if (editorService.ShowDialog(dialog) == DialogResult.OK)
                        {
                            valueString = dialog.ImagePath;

                            if (!string.IsNullOrEmpty(valueString))
                            {
                                value = valueString;
                            }
                        }
                    }
                }
            }

            return(CreateItemReference(value));
        }