Пример #1
0
        /// <summary>
        /// Modifies the given html image (parameterwise).
        /// </summary>
        public void ModifyHtmlImage(HtmlImage image)
        {
            IParentModelElement parent = this.ViewModelStore.GetDomainModelServices(this.Elements[0] as ModelElement).ElementParentProvider.GetParentModelElement(this.Elements[0] as ModelElement);

            if (parent == null)
            {
                throw new ArgumentNullException("Parent of element " + this.Elements[0].ToString() + " can not be null");
            }
            string path          = parent.DomainFilePath;
            string referencePath = new System.IO.FileInfo(path).DirectoryName;

            //string referencePath = this.ViewModelStore.GetDomainModelServices(this.Elements[0] as ModelElement).ElementParentProvider.GetDomainModelDirectory(this.Elements[0] as ModelElement);

            using (HtmlInsertImageViewModel vm = new HtmlInsertImageViewModel(this.ViewModelStore, referencePath))
            {
                vm.RelativePath     = image.RelativeSource;
                vm.AlternativeText  = image.AlternativeText;
                vm.ImageId          = image.Id;
                vm.ExportHeight     = image.ExportHeight;
                vm.ExportWidth      = image.ExportWidth;
                vm.SourcePath       = referencePath + "\\" + vm.RelativePath;
                vm.IsInsertionValid = true;

                vm.Title = "Edit image";

                bool?result = this.GlobalServiceProvider.Resolve <IUIVisualizerService>().ShowDialog("InsertImagePopup", vm);
                if (result == true)
                {
                    image.RelativeSource  = vm.RelativePath;
                    image.AlternativeText = vm.AlternativeText;
                    image.Id           = vm.ImageId;
                    image.ExportHeight = vm.ExportHeight;
                    image.ExportWidth  = vm.ExportWidth;

                    try
                    {
                        // try to load image
                        BitmapImage bimg = new BitmapImage();
                        bimg.BeginInit();
                        bimg.UriSource = new Uri(referencePath + "\\" + image.RelativeSource, UriKind.Absolute);
                        bimg.EndInit();

                        image.Source = bimg;
                    }
                    catch
                    {
                    }
                }
            }
            GC.Collect();
        }
        /// <summary>
        /// Insert image command executed.
        /// </summary>
        private void HtmlInsertImageCommand_Executed()
        {
            IParentModelElement parent = this.ViewModelStore.GetDomainModelServices(this.Elements[0] as ModelElement).ElementParentProvider.GetParentModelElement(this.Elements[0] as ModelElement);
            if (parent == null)
                throw new ArgumentNullException("Parent of element " + this.Elements[0].ToString() + " can not be null");
            string path = parent.DomainFilePath;
            string referencePath = new System.IO.FileInfo(path).DirectoryName;

            //string referencePath = this.ViewModelStore.GetDomainModelServices(this.Elements[0] as ModelElement).ElementParentProvider.GetDomainModelDirectory(this.Elements[0] as ModelElement);
            using (HtmlInsertImageViewModel vm = new HtmlInsertImageViewModel(this.ViewModelStore, referencePath))
            {
            vm.Title = "Insert new image";

            bool? result = this.GlobalServiceProvider.Resolve<IUIVisualizerService>().ShowDialog("InsertImagePopup", vm);
            if (result == true)
            {
                HtmlImage image = new HtmlImage();
                image.RelativeSource = vm.RelativePath;
                image.AlternativeText = vm.AlternativeText;
                image.Id = vm.ImageId;
                image.ExportHeight = vm.ExportHeight;
                image.ExportWidth = vm.ExportWidth;

                try
                {
                    // try to load image
                    BitmapImage bimg = new BitmapImage();
                    bimg.BeginInit();
                    bimg.UriSource = new Uri(referencePath + "\\" + image.RelativeSource, UriKind.Absolute);
                    bimg.EndInit();

                    image.Source = bimg;
                }
                catch
                {

                }

                if (this.HtmlRichTextEditor != null)
                    this.HtmlRichTextEditor.InsertImage(image);
            }
            }
            GC.Collect();
        }