Example #1
0
        private void btnHyperlink_Click(object sender, RoutedEventArgs e)
        {
            //rtb.DisplayActionDefinition();
            InsertURL cw = new InsertURL(rtb.Selection.Text, false);

            cw.HasCloseButton = false;
            cw.Closed        += (s, args) =>
            {
                if (cw.DialogResult.Value)
                {
                    Hyperlink hyperlink = new Hyperlink();
                    hyperlink.TargetName  = "_blank";
                    hyperlink.NavigateUri = new Uri(cw.txtURL.Text);

                    //if (cw.txtURLDesc.Text.Length > 0)
                    //    hyperlink.Inlines.Add(cw.txtURLDesc.Text);
                    //else
                    hyperlink.Inlines.Add(cw.txtURL.Text);

                    rtb.Selection.Insert(hyperlink);
                }
            };

            cw.Show();
        }
Example #2
0
        private void btnImage_Click(object sender, RoutedEventArgs e)
        {
            //Uri imageUri = new Uri("http://t3.baidu.com/it/u=2499248362,4035544451&fm=0&gp=0.jpg", UriKind.RelativeOrAbsolute);
            //InlineUIContainer container = new InlineUIContainer();
            ////  System.Windows.Documents.TextElement.
            //container.Child = CreateImageFromUri(imageUri, 200, 150);
            //rtb.Selection.Insert(container);

            //ReturnFocus();


            InsertURL cw = new InsertURL(rtb.Selection.Text, true);

            cw.HasCloseButton = false;
            cw.Closed        += (s, args) =>
            {
                if (cw.DialogResult.Value)
                {
                    InlineUIContainer container = new InlineUIContainer();
                    int w = 200;
                    int.TryParse(cw.txtWidth.Text, out w);  //图片宽度
                    int h = 150;
                    int.TryParse(cw.txtHeight.Text, out h); //图片高度

                    //输入图片路径
                    if (cw.fs != null)
                    {
                        BitmapImage bmp = null;
                        try
                        {
                            bmp = cw.bmp;
                            Image img = new Image();
                            img.Stretch = Stretch.Uniform;
                            img.Width   = w;
                            img.Height  = h; //图片高度
                            img.Source  = bmp;
                            img.Tag     = bmp.UriSource.ToString();
                            //  bmp.DownloadProgress += new EventHandler<DownloadProgressEventArgs>(bmp_DownloadProgress);
                            container.Child = img;
                            rtb.Selection.Insert(container);
                            ReturnFocus();
                        }
                        catch
                        {
                            bmp = null;
                        }
                    }
                    else
                    {
                        string url = cw.txtURL.Text;
                        //添加图片插入到InlineUIContainer之中
                        Uri imageUri = new Uri(url, UriKind.RelativeOrAbsolute);
                        container.Child = Utility.CreateImageFromUri(imageUri, w, h);
                        rtb.Selection.Insert(container);
                        ReturnFocus();
                    }
                }
            };
            cw.Show();
        }