Ejemplo n.º 1
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}", SoonLearning.Assessment.Player.Properties.Resources.txtLoadPictureFailed, imageProperties.ImageHyperlink, ex), SoonLearning.Assessment.Player.Properties.Resources.txtEditorName);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static void OnInsertPicture(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextEditor control     = (RichTextEditor)sender;
            RichTextBox    richTextBox = control.RichTextBox;

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

            Image image = Helper.GetImageAncestor(textPosition);

            if (null != image)
            {
                if (image.Tag is string)
                {
                    string tag = image.Tag as string;
                    if (!tag.StartsWith("_$FRACTION_"))
                    {
                        PictureCommands.OnEditPictureProperties(sender, e);
                        return;
                    }
                }
                else
                {
                    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);
                    paragraph.Inlines.LastInline.BaselineAlignment = BaselineAlignment.Center;

                    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}", SoonLearning.Assessment.Player.Properties.Resources.txtLoadPictureFailed, imageProperties.ImageHyperlink, ex),
                                    SoonLearning.Assessment.Player.Properties.Resources.txtEditorName);
                }
            }
        }