private void textRadioButton_Click(object sender, RoutedEventArgs e) { TextboxInkcavasUserControl t = textboxInkcavasUserControl; t.inkCanvas.SetValue(Grid.ZIndexProperty, 0); t.paragraphRichTextBox.SetValue(Grid.ZIndexProperty, 1); }
private void pageLoad(int start, int sectionLength) { pageTextBox.Text = (start / sectionLength + 1).ToString(); //按语段+关键字循环 for (int i = 0; i < sectionLength; i++) { if (startPoint + i < length) { int paraId = paragraphIdKeywords[startPoint + i].paragraphId; string gjc = paragraphIdKeywords[startPoint + i].keyword; var paragraph = from data_item in yd_dt where data_item.ID == paraId select data_item; foreach (var para in paragraph) { //语段编号 textBlock = new TextBlock(); textBlock.Inlines.Add(new Run(para.ID.ToString() + ":" + gjc) { Foreground = Brushes.Red }); paperStackPanel.Children.Add(textBlock); //文本框 if (para["分类"].ToString() != "图片语段") { string path_isf = ""; path_isf = para.语段isf; if (path_isf == "") { //保存数据库 para.语段isf = @".\科学研究\语段ISF\" + para.ID + ".isf"; yd_ta.Update(yd_dt); path_isf = para.语段isf; } textboxInkcavasUserControl = new TextboxInkcavasUserControl(path_isf); textboxInkcavasUserControl.GotFocus += textboxInkcavasUserControl_GotFocus; textboxInkcavasUserControl.StylusDown += TextboxInkcavasUserControl_StylusDown; textboxInkcavasUserControl.PreviewMouseLeftButtonDown += TextboxInkcavasUserControl_PreviewMouseLeftButtonDown; textboxInkcavasUserControl.yd_dt = yd_dt; textboxInkcavasUserControl.yd_ta = yd_ta; double width = para.宽度; if (width > 0) { textboxInkcavasUserControl.paragraphRichTextBox.Width = width; textboxInkcavasUserControl.inkCanvas.Width = width; } else { textboxInkcavasUserControl.paragraphRichTextBox.Width = MainWindow.yd_cz_width; textboxInkcavasUserControl.inkCanvas.Width = MainWindow.yd_cz_width; } //Binding binding = new Binding(); //binding.Source = para; //binding.Path = new PropertyPath("语段"); //binding.Mode = BindingMode.TwoWay; //textboxInkcavasUserControl.paragraphRichTextBox.SetBinding(TextBox.TextProperty, binding); string yd_xaml = para.语段; string condition = yd_xaml.Substring(0, 13); if (condition == "<FlowDocument") { textboxInkcavasUserControl.paragraphRichTextBox.Document = xamlManageClass.xaml_load(yd_xaml); } else { FlowDocument doc = new FlowDocument(); doc.LineHeight = 10; Paragraph p = new Paragraph(); p.LineHeight = 30; Run r = new Run(para.语段); //r.SetBinding(Run.TextProperty, binding); p.Inlines.Add(r); doc.Blocks.Add(p); textboxInkcavasUserControl.paragraphRichTextBox.Document = doc; } paperStackPanel.Children.Add(textboxInkcavasUserControl); textboxInkcavasUserControl.yd_id = para.ID; } else { string figure_path = ""; string figure_path_isf = ""; var data4 = from data_item in yd_dt where data_item.ID == para.ID select data_item; foreach (var d4 in data4) { figure_path = d4.图片.ToString(); figure_path_isf = d4.图片isf.ToString(); } figure_path = MainWindow.path_translate(figure_path); figure_path_isf = MainWindow.path_translate(figure_path_isf); ParagraphFigureUserControl paragraphFigureUserControl = new ParagraphFigureUserControl(); if (File.Exists(figure_path)) { //存在图片 //BitmapImage img = new BitmapImage(); //img.BeginInit(); //img.CacheOption = BitmapCacheOption.OnLoad; //img.UriSource = new Uri(figure_path); //img.EndInit(); //ImageSource img = new BitmapImage(new Uri(figure_path, UriKind.RelativeOrAbsolute)); //ImageSource img2=img.Clone(); BitmapImage bitmapImage; BinaryReader reader = new BinaryReader(File.Open(figure_path, FileMode.Open)); FileInfo fi = new FileInfo(figure_path); byte[] bytes = reader.ReadBytes((int)fi.Length); reader.Close(); bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = new MemoryStream(bytes); bitmapImage.EndInit(); paragraphFigureUserControl.img.Source = bitmapImage; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; } else { //不存在图片的时候 } paragraphFigureUserControl.grid.RowDefinitions[0].Height = new GridLength(0); paragraphFigureUserControl.paragraphId = para.ID; paragraphFigureUserControl.GotFocus += ParagraphFigureUserControl_GotFocus; paragraphFigureUserControl.StylusDown += ParagraphFigureUserControl_StylusDown; if (File.Exists(figure_path_isf)) { FileStream file_ink = new FileStream(figure_path_isf, FileMode.OpenOrCreate); if (file_ink.Length != 0) { paragraphFigureUserControl.canvas.Strokes = new StrokeCollection(file_ink); } file_ink.Close(); paragraphFigureUserControl.figure_path_isf = figure_path_isf; } else { paragraphFigureUserControl.canvas.Strokes.Clear(); figure_path_isf = ".\\科学研究\\图片ISF\\" + para.ID + ".isf"; //更新数据库 var data5 = from data_item in yd_dt where data_item.ID == para.ID select data_item; foreach (var d5 in data5) { d5.图片isf = figure_path_isf; yd_ta.Update(yd_dt); } //更新墨笔文件路径 figure_path_isf = MainWindow.path_translate(figure_path_isf); paragraphFigureUserControl.figure_path_isf = figure_path_isf; } paperStackPanel.Children.Add(paragraphFigureUserControl); } //所有参考语段的图片 var data3 = from gjc2 in gjc_dt join yd_gjc in yd_gjc_dt on gjc2.ID equals yd_gjc.关键词ID join yd in yd_dt on yd_gjc.语段ID equals yd.ID where gjc2.关键词 == gjc select new ParagraphID { 语段ID = yd.ID }; foreach (var d3 in data3) { textBlock = new TextBlock(); textBlock.Text = d3.语段ID.ToString(); paperStackPanel.Children.Add(textBlock); string figure_path = ""; string figure_path_isf = ""; var data4 = from data_item in yd_dt where data_item.ID == d3.语段ID select data_item; foreach (var d4 in data4) { try { figure_path = d4.图片.ToString(); figure_path_isf = d4.图片isf.ToString(); } catch { } finally { } } figure_path = MainWindow.path_translate(figure_path); figure_path_isf = MainWindow.path_translate(figure_path_isf); if (File.Exists(figure_path)) { ImageSource img = new BitmapImage(new Uri(figure_path, UriKind.RelativeOrAbsolute)); ParagraphFigureUserControl p = new ParagraphFigureUserControl(); p.img.Source = img; p.grid.RowDefinitions[0].Height = new GridLength(0); if (File.Exists(figure_path_isf)) { FileStream file_ink = new FileStream(figure_path_isf, FileMode.OpenOrCreate); if (file_ink.Length != 0) { p.canvas.Strokes = new StrokeCollection(file_ink); } file_ink.Close(); p.figure_path_isf = figure_path_isf; } else { p.canvas.Strokes.Clear(); figure_path_isf = ".\\科学研究\\图片ISF\\" + d3.语段ID.ToString() + ".isf"; //更新数据库 var data5 = from data_item in yd_dt where data_item.ID == d3.语段ID select data_item; foreach (var d5 in data5) { d5.图片isf = figure_path_isf; yd_ta.Update(yd_dt); } //更新墨笔文件路径 figure_path_isf = MainWindow.path_translate(figure_path_isf); p.figure_path_isf = figure_path_isf; } paperStackPanel.Children.Add(p); } } } } } foreach (object t in paperStackPanel.Children) { string name = t.GetType().FullName; if (name == "ScienceResearchWpfApplication.TextManage.TextboxInkcavasUserControl") { ((TextboxInkcavasUserControl)t).inkCanvas.SetValue(Grid.ZIndexProperty, 1); ((TextboxInkcavasUserControl)t).paragraphRichTextBox.SetValue(Grid.ZIndexProperty, 0); } } }