Пример #1
0
        // Eventhandler to add a hyperlink inside the post
        private void _btnLink_Click(object sender, RoutedEventArgs e)
        {
            TextSelection ts    = tekst.Selection;
            TextPointer   start = ts.Start;
            TextPointer   end   = ts.End;

            TextRange before = new TextRange(tekst.Document.ContentStart, start);
            TextRange after  = new TextRange(end, tekst.Document.ContentEnd);
            TextRange linker = new TextRange(start, end);

            Paragraph myParagraph = new Paragraph();

            myParagraph.Inlines.Clear();
            myParagraph.Inlines.Add(before.Text);

            Hyperlink hyperLink = new Hyperlink();

            hyperLink.IsEnabled = true;

            // ask the user for an URL
            var dialog = new MyDialog();

            dialog.SomeData = "Enter a valid URL (like ww.example.com)";
            // If MyDialog has properties that affect its behavior, set them here
            var    result = dialog.ShowDialog();
            string link   = "";

            if (result == false)
            {
                // cancelled
            }
            else if (result == true)
            {
                link = dialog.SomeData;
                link = "http://" + link;

                hyperLink.NavigateUri = new Uri(link);
                hyperLink.Inlines.Add(ts.Text);

                myParagraph.Inlines.Add(hyperLink);
                myParagraph.Inlines.Add(after.Text);

                tekst.Document.Blocks.Clear();

                tekst.Document.Blocks.Add(myParagraph);
            }
        }
Пример #2
0
        // Eventhandler to add a YouTube-video inside the post
        private void _btnYT_Click(object sender, RoutedEventArgs e)
        {
            TextSelection ts    = tekst.Selection;
            TextPointer   start = ts.Start;
            TextPointer   end   = ts.End;

            TextRange before = new TextRange(tekst.Document.ContentStart, start);
            TextRange after  = new TextRange(end, tekst.Document.ContentEnd);
            TextRange linker = new TextRange(start, end);

            Paragraph myParagraph = new Paragraph();

            myParagraph.Inlines.Clear();
            myParagraph.Inlines.Add(before.Text);


            var dialog = new MyDialog();

            dialog.SomeData = "Enter a YouTube ID";
            // If MyDialog has properties that affect its behavior, set them here
            var    result = dialog.ShowDialog();
            string link   = "";

            if (result == false)
            {
                // cancelled
            }
            else if (result == true)
            {
                link = dialog.SomeData;

                Run run = new Run();
                run.Foreground = Brushes.Red;
                run.Text       = "[YOUTUBE]" + link + "[/YOUTUBE]";

                myParagraph.Inlines.Add(run);
                myParagraph.Inlines.Add(after.Text);

                tekst.Document.Blocks.Clear();

                tekst.Document.Blocks.Add(myParagraph);
            }
        }