Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
how can i convert Visual object to WPF contols.here i need to
convert (element.GetType().Name == "ParagraphVisual") back to
paragraph.

C#
public override DocumentPage GetPage(int pageNumber) {
     DocumentPage page = paginator.GetPage(pageNumber);
     DrawingVisual newpage = new DrawingVisual();
     ContainerVisual header = GetPartVisual();
     newpage.Children.Add(header);
     ContainerVisual footer = new ContainerVisual();
     header.Children.Add(XpsReport.GetFooter(pageSize.Width,pageSize.Height));
      PageStartsWithTable(paginator.GetPage(pageNumber).Visual);
     ContainerVisual smallerPage = new ContainerVisual();
     smallerPage.Children.Add(page.Visual);
     smallerPage.Transform = new MatrixTransform(1,0,0,1,0,100);
     newpage.Children.Add(smallerPage);
     newpage.Transform = new TranslateTransform(margin.Width,margin.Height);
     return new DocumentPage(newpage,pageSize,page.BleedBox,page.ContentBox);
   }


private bool PageStartsWithTable(DependencyObject element)
   {
     ContainerVisual tableVisual;
     tableVisual = null;
     if (element.GetType().Name == "ParagraphVisual")//i need to convert it back to paragraph.
     {
       // Paragraph paragraph =(Paragraph)element;
     tableVisual = (ContainerVisual)VisualTreeHelper.GetParent(element);
       return true;
     }
     if (VisualTreeHelper.GetChildrenCount(element) > 0) {
       DependencyObject child = VisualTreeHelper.GetChild(element,0);
       if (PageStartsWithTable(child)) {
         return true;
       }
     }
     return false;
   }
Posted
Updated 22-Feb-12 0:33am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900