Example #1
0
        public static void OnInsertPicture(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextEditor control     = (RichTextEditor)sender;
            RichTextBox    richTextBox = control.RichTextBox;

            //###
            TextPointer textPosition = richTextBox.Selection.Start;

            if (null != Helper.GetImageAncestor(textPosition))
            {
                PictureCommands.OnEditPictureProperties(sender, e);
                return;
            }
            //###

            if (!richTextBox.Selection.IsEmpty)
            {
                richTextBox.Selection.Text = String.Empty;
            }

            TextPointer insertionPosition = richTextBox.Selection.Start;


            ImagePropertiesDialog imageProperties = new ImagePropertiesDialog(null);

            imageProperties.ShowDialog();

            if (true == imageProperties.DialogResult)
            {
                try
                {
                    Paragraph paragraph = insertionPosition.Paragraph;

                    // Split current paragraph at insertion position
                    insertionPosition = insertionPosition.InsertParagraphBreak();
                    paragraph         = insertionPosition.Paragraph;
                    //paragraph.Inlines.Add("Some ");

                    //AcmBitmapImageHolder acmBitmapImageHolder = new AcmBitmapImageHolder(new Uri(@"http://www.cetelem.cz/images/cetelem2/cetelem_logo_cl_small.gif"));
                    AcmBitmapImageHolder acmBitmapImageHolder = new AcmBitmapImageHolder(new Uri(imageProperties.ImagePath));

                    //acmBitmapImageHolder.Image.Style= sender.
                    paragraph.Inlines.Add(acmBitmapImageHolder.Image);

                    if (!String.IsNullOrEmpty(imageProperties.ImageHyperlink))
                    {
                        //### Set hyperlink
                        acmBitmapImageHolder.Image.Tag = imageProperties.ImageHyperlink;
                        Hyperlink hyperlink = new Hyperlink(paragraph.Inlines.LastInline, insertionPosition);
                        hyperlink.NavigateUri = new Uri(imageProperties.ImageHyperlink);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(String.Format("{0} ({1}) :\n\r{2}", Res.txtLoadPictureFailed, imageProperties.ImageHyperlink, ex), Res.txtEditorName);
                }
            }
        }
 /// <summary>
 /// SetDefaults button click handler
 /// </summary>
 private void OnSetDefaultsClick(object sender, RoutedEventArgs e)
 {
     //AcmBitmapImageHolder acmBitmapImageHolder = new AcmBitmapImageHolder(this.Image,((BitmapImage)this.Image.Source).UriSource);
     try
     {
         BitmapSource bitmapSource = this.Image.Source as BitmapSource;
         if (null != bitmapSource)
         {
             AcmBitmapImageHolder acmBitmapImageHolder = new AcmBitmapImageHolder(this.Image, new Uri(bitmapSource.ToString()));
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("OnSetDefaultsClick ex: " + ex);
     }
     //this.BindImage(acmBitmapImageHolder.Image);
 }
Example #3
0
        /// <summary>
        /// Handler for editing of the picture
        /// </summary>
        public static void OnEditPictureProperties(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextEditor control           = (RichTextEditor)sender;
            RichTextBox    richTextBox       = control.RichTextBox;
            TextPointer    insertionPosition = richTextBox.Selection.Start;

            Image             image             = Helper.GetImageAncestor(insertionPosition);
            InlineUIContainer inlineUIContainer = Helper.GetInlineUIContainer(insertionPosition);

            if (image != null)
            {
                ImagePropertiesDialog imageProperties = new ImagePropertiesDialog(image);
                imageProperties.ShowDialog();
                if (true == imageProperties.DialogResult)
                {
                    try
                    {
                        if (imageProperties.PictureSourceChanged)
                        {
                            AcmBitmapImageHolder acmBitmapImageHolder = new AcmBitmapImageHolder(image, new Uri(imageProperties.ImagePath));
                        }
                        if (!String.IsNullOrEmpty(imageProperties.ImageHyperlink))
                        {
                            //### Set hyperlink
                            image.Tag = imageProperties.ImageHyperlink;
                            Hyperlink hyperlink = new Hyperlink(inlineUIContainer, insertionPosition);
                            hyperlink.NavigateUri = new Uri(imageProperties.ImageHyperlink);
                        }
                        control.OnRichTextBox_TextChanged(control, null);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(String.Format("{0} ({1}) :\n\r{2}", Res.txtLoadPictureFailed, imageProperties.ImageHyperlink, ex), Res.txtEditorName);
                    }
                }
            }
        }
 /// <summary>
 /// SetDefaults button click handler
 /// </summary>
 private void OnSetDefaultsClick(object sender, RoutedEventArgs e)
 {
     //AcmBitmapImageHolder acmBitmapImageHolder = new AcmBitmapImageHolder(this.Image,((BitmapImage)this.Image.Source).UriSource);
     try
     {
         BitmapSource bitmapSource = this.Image.Source as BitmapSource;
         if (null != bitmapSource)
         {
             AcmBitmapImageHolder acmBitmapImageHolder = new AcmBitmapImageHolder(this.Image, new Uri(bitmapSource.ToString()));
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("OnSetDefaultsClick ex: "+ex);
     }
     //this.BindImage(acmBitmapImageHolder.Image);
 }
        /// <summary>
        /// Handler for editing of the picture
        /// </summary>
        public static void OnEditPictureProperties(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextEditor control = (RichTextEditor)sender;
            RichTextBox richTextBox = control.RichTextBox;
            TextPointer insertionPosition = richTextBox.Selection.Start;

            Image image = Helper.GetImageAncestor(insertionPosition);
            InlineUIContainer inlineUIContainer = Helper.GetInlineUIContainer(insertionPosition);
            if (image != null)
            {
                ImagePropertiesDialog imageProperties = new ImagePropertiesDialog(image);
                imageProperties.ShowDialog();
                if (true == imageProperties.DialogResult)
                {
                    try
                    {
                        if (imageProperties.PictureSourceChanged)
                        {
                            AcmBitmapImageHolder acmBitmapImageHolder = new AcmBitmapImageHolder(image,new Uri(imageProperties.ImagePath));
                        }
                        if (!String.IsNullOrEmpty(imageProperties.ImageHyperlink))
                        {
                            //### Set hyperlink
                            image.Tag = imageProperties.ImageHyperlink;
                            Hyperlink hyperlink = new Hyperlink(inlineUIContainer,insertionPosition);
                            hyperlink.NavigateUri = new Uri(imageProperties.ImageHyperlink);
                        }
                        control.OnRichTextBox_TextChanged(control, null);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(String.Format("{0} ({1}) :\n\r{2}",Res.txtLoadPictureFailed,imageProperties.ImageHyperlink,ex), Res.txtEditorName);
                    }
                }
            }
        }
        public static void OnInsertPicture(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextEditor control = (RichTextEditor)sender;
            RichTextBox richTextBox = control.RichTextBox;

            //###
            TextPointer textPosition = richTextBox.Selection.Start;

            if (null != Helper.GetImageAncestor(textPosition))
            {
                PictureCommands.OnEditPictureProperties(sender, e);
                return;
            }
            //###

            if (!richTextBox.Selection.IsEmpty)
            {
                richTextBox.Selection.Text = String.Empty;
            }

            TextPointer insertionPosition = richTextBox.Selection.Start;


            ImagePropertiesDialog imageProperties = new ImagePropertiesDialog(null);
            imageProperties.ShowDialog();

            if (true == imageProperties.DialogResult)
            {
                try
                {
                    Paragraph paragraph = insertionPosition.Paragraph;

                    // Split current paragraph at insertion position
                    insertionPosition = insertionPosition.InsertParagraphBreak();
                    paragraph = insertionPosition.Paragraph;
                    //paragraph.Inlines.Add("Some ");

                    //AcmBitmapImageHolder acmBitmapImageHolder = new AcmBitmapImageHolder(new Uri(@"http://www.cetelem.cz/images/cetelem2/cetelem_logo_cl_small.gif"));
                    AcmBitmapImageHolder acmBitmapImageHolder = new AcmBitmapImageHolder(new Uri(imageProperties.ImagePath));

                    //acmBitmapImageHolder.Image.Style= sender.
                    paragraph.Inlines.Add(acmBitmapImageHolder.Image);

                    if (!String.IsNullOrEmpty(imageProperties.ImageHyperlink))
                    {
                        //### Set hyperlink
                        acmBitmapImageHolder.Image.Tag = imageProperties.ImageHyperlink;
                        Hyperlink hyperlink = new Hyperlink(paragraph.Inlines.LastInline, insertionPosition);
                        hyperlink.NavigateUri = new Uri(imageProperties.ImageHyperlink);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(String.Format("{0} ({1}) :\n\r{2}",Res.txtLoadPictureFailed,imageProperties.ImageHyperlink,ex), Res.txtEditorName);
                }
            }
        }