locked
My 1st WPF (XBAP) application.. Please Help!! RRS feed

  • Question

  • Hi there,

    This is my first attempt at developing using WPF. My web development experience is limited to ASP.net, so you can imagine how I'm feeling when I'm trying to develop my 1st WPF (XBAP) application.

     

    This is what I have to do:

    I have an html file that I need to use as a layout for my WPF web app, and then add WPF controls (such a charts and sliders to it). 

    So, I attempted to firstly deal with the layout issue and convert the html into xaml. I found this HTMLToXamlCoverter tool here . I converted the html using the tool and I got a FlowDocument.

    Now, from what I understand (please correct if I'm wrong), I need to use a control to display the content of the FlowDocument, and it seems there are 3 ways to accomplish that:
    - FlowDocumentReader
    - FlowDocumentPageViewer
    - FlowDocumentScrollViewer

    Now, I have no idea how to proceed from here. I tried the following, but obviously it doesn't work.

    I created these 2 pages:

    Page1.xaml

     

    <
    Page
     x:Class
    =
    "
    Dashboard_Demo1.Page1
    "
    
      xmlns
    =
    "
    http://schemas.microsoft.com/winfx/2006/xaml/presentation
    "
    
      xmlns:x
    =
    "
    http://schemas.microsoft.com/winfx/2006/xaml
    "
    
      xmlns:mc
    =
    "
    http://schemas.openxmlformats.org/markup-compatibility/2006
    "
     
      xmlns:d
    =
    "
    http://schemas.microsoft.com/expression/blend/2008
    "
     
      mc:Ignorable
    =
    "
    d
    "
     
      d:DesignHeight
    =
    "
    300
    "
     d:DesignWidth
    =
    "
    300
    "
    
    	Title
    =
    "
    Page1
    "
    >
    
     <
    Grid
    >
    
      <
    FlowDocumentReader
    
       Name
    =
    "
    flowDocRdr
    "
     
      />
    
     </
    Grid
    >
    
    </
    Page
    >
    
    
    

     

     

    and Page1.xaml.cs

     

    using
     System;
    using
     System.Collections.Generic;
    using
     System.Linq;
    using
     System.Text;
    using
     System.Windows;
    using
     System.Windows.Controls;
    using
     System.Windows.Data;
    using
     System.Windows.Documents;
    using
     System.Windows.Input;
    using
     System.Windows.Media;
    using
     System.Windows.Media.Imaging;
    using
     System.Windows.Navigation;
    using
     System.Windows.Shapes;
    using
     System.IO;
    using
     System.Windows.Markup;
    
    namespace
     Dashboard_Demo1
    {
     ///
     <summary>
    
     ///
     Interaction logic for Page1.xaml
    
     ///
     </summary>
    
     public
     partial
     class
     Page1 : Page
     {
      public
     Page1()
      {
       InitializeComponent();
       LoadFlowDocumentReaderWithXAMLFile("FlowDocument1.xaml"
    );
    
      }
      void
     LoadFlowDocumentReaderWithXAMLFile(string
     fileName)
      {
       // Open the file that contains the FlowDocument...
    
       FileStream xamlFile = new
     FileStream(fileName, FileMode.Open, FileAccess.Read);
       // and parse the file with the XamlReader.Load method.
    
       FlowDocument content = XamlReader.Load(xamlFile) as
     FlowDocument;
       // Finally, set the Document property to the FlowDocument object that was
    
       // parsed from the input file.
    
       flowDocRdr.Document = content;
    
       xamlFile.Close();
      }
     }
    }
    
    

     

     

    Now, when I tried to run this, I got a blank page.

     

    I'm pretty sure I don't understand exactly how WPF/XAML works (in contrast to asp.net), or I might have missed a step above... I don't really know :(

     

    Any pointers would be greatly appreciated!!

     

    Friday, March 4, 2011 11:56 PM

Answers

  • The converter you found does not do what you think it does.  The HTMLToXAMLCOnverter is meant for converting HTML text into a Flowdocument normally meant for things like a RichTextBox.  There is no tool currently that will conver an ASP.NET web page and convert it to XAML.  You will have to use panel controls such as a Grid and StackPanel to layout your WPF view.

    start here: http://windowsclient.net/learn/videos_wpf.aspx

    • Proposed as answer by Yves.Z Tuesday, March 8, 2011 9:35 AM
    • Marked as answer by Sheldon _Xiao Wednesday, March 16, 2011 6:42 AM
    Saturday, March 5, 2011 12:30 AM

All replies

  • The converter you found does not do what you think it does.  The HTMLToXAMLCOnverter is meant for converting HTML text into a Flowdocument normally meant for things like a RichTextBox.  There is no tool currently that will conver an ASP.NET web page and convert it to XAML.  You will have to use panel controls such as a Grid and StackPanel to layout your WPF view.

    start here: http://windowsclient.net/learn/videos_wpf.aspx

    • Proposed as answer by Yves.Z Tuesday, March 8, 2011 9:35 AM
    • Marked as answer by Sheldon _Xiao Wednesday, March 16, 2011 6:42 AM
    Saturday, March 5, 2011 12:30 AM
  • Hi volcano_888,

    I am marking your issue as "Answered", if you have new finding about your issue, please let me know.

     

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, March 16, 2011 6:42 AM