1

Below is a sample XML which I want to read and create a few GUIs based on these structures at runtime, (the basic idea is to read the fields from a XML file and create the screen for the user input).

I have written some sample code which creats the screen at run time, however i am not sure how o do this when i wish to read the fields from the XML file.

Any help is really appreciated.

Below is the sample C# code to do this (I want to do this in WPF).

private void Init()
{
    StackPanel spParent = new StackPanel();
    StackPanel sp;
    for (int i = 0; i < 5; i++)
    {
        sp = CreateLabelTextPair(i);
        spParent.Children.Add(sp);
    }
    spParent.Orientation = Orientation.Vertical;
    spParent.Margin = new Thickness(2);

    this.Content = spParent;
    this.Height = spParent.Height + 10;
    this.Width = spParent.Width + 10;
}

StackPanel CreateLabelTextPair(int i)
{
    StackPanel sp = new StackPanel();

    Label lbl = new Label();
    lbl.Height = 25;
    lbl.Width = 100;
    lbl.Content = "Label" + (i+1);
    sp.Children.Add(lbl);

    sp.Margin = new Thickness(2);

    TextBox tb = new TextBox();
    tb.Height = 25;
    tb.Width = 100;
    tb.Text = "TextBox" + (i+1);
    sp.Children.Add(tb);

    sp.Height = lbl.Height;
    sp.Width = lbl.Width+tb.Width+10;

    sp.Orientation = Orientation.Horizontal;
    return sp;
}

Below is the sample XML (which i wish to read and create the GUI look like a data entry screen).

  <DataSet>
      <Data>
        <Field1>Name</Field1>
        <Field2>DataType</Field2>
        <Field3>Length</Field3>
        <Field4>DefaultValue</Field4>
        <Field5>IsNull</Field5>
        <Field6>Precesion</Field6>
      </Data>
  </DataSet>

1 Answer 1

3

First things first. Since you want create WPF, why don't you use XSLT to transform your xml into XAML.

However if this more than you need then have a look at Linq2Xml.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.