locked
Please point me to the right direction for doing these things RRS feed

  • Question

  • (1) Suppose I have a usercontrol that is referenced in the main xaml page.  There is a button.  Every time the user presses this button, I want to create a new instance of the usercontrol so the user can do a new instance of this calculation. 

    For example, the user wants to measure a table so he creates a new instance of this usercontrol and then he inputs the dimensions of the table.  Then he goes on to the next table or chair and so he presses the button and creates a new instance of this usercontrol to input the dimensions for this next thing.  Then he goes on and so on and so forth.

    Please tell me how I can achieve this. 

    (2) When the user is done and he has input like 10 or however how many object measurements, he wants to print exactly what he sees on the screen into a pdf file.  How do I do this?  Is there a pdf conversion library or function that can convert exactly what's on the screen into a pdf page?

    (3) On the main page, I want to be able to communicate with the variables in the usercontrol.  So, when the user inputs leg length of a table, on the main page at the bottom there is a text box that outputs the total leg lengths of all the tables.  How will I achieve this?

    Thank you for your help.

    Sunday, October 20, 2013 3:18 AM

Answers

  • Here are pointers:
    1) If you have a button that creates a new object, and the object requires parameters/properties...

    void ButtonClickedMethod ()
    {
       var MyParameters  = ShowDialogThatGetsParametersAndReturnsThem();
       var MyNewObject = new Object(Parameter) {ObjectProperty1 = MyParameters.Property, ObjectProperty2 = MyParameters.Property2};
       XAMLObjectParent.Children.Add(MyNewObject);
    }

    2) Use this sample (http://code.msdn.microsoft.com/windowsapps/XAML-render-to-bitmap-dd4f549f) to render to a bitmap.  Then find a third-party library that converts from bitmap to PDF.

    3) A few different ways to handle this.  Every time that you add a new leg length, you also add all of the legs together and update the text box.  That would be pretty simple.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, October 21, 2013 12:19 PM
    Moderator
  • Something like this:

    // In the UserControl
    Public List<Leg> MyListOfAllLegs= new List<Leg>();

    Public void AddNewLegToTable (int LegLength, Table TableWhichToAddLeg)

    {
        Leg NewLeg = new Leg(LegLength);
        TableToWhichAddLeg.AddNewLeg(NewLeg, Table.FrontLeftLeg);
        MyListOfAllLegs.Add(NewLeg);

    }

    // IN the MainPage
    Public int TotalLengthOfLegs ()
    {
          int TotalLength = 0;
          foreach (Leg L in UserControl.ListOfAllLegs)
          {
              TotalLength += L.Length;
           }
           Return TotalLength;

    }


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, November 4, 2013 1:47 PM
    Moderator

All replies

  • Here are pointers:
    1) If you have a button that creates a new object, and the object requires parameters/properties...

    void ButtonClickedMethod ()
    {
       var MyParameters  = ShowDialogThatGetsParametersAndReturnsThem();
       var MyNewObject = new Object(Parameter) {ObjectProperty1 = MyParameters.Property, ObjectProperty2 = MyParameters.Property2};
       XAMLObjectParent.Children.Add(MyNewObject);
    }

    2) Use this sample (http://code.msdn.microsoft.com/windowsapps/XAML-render-to-bitmap-dd4f549f) to render to a bitmap.  Then find a third-party library that converts from bitmap to PDF.

    3) A few different ways to handle this.  Every time that you add a new leg length, you also add all of the legs together and update the text box.  That would be pretty simple.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, October 21, 2013 12:19 PM
    Moderator
  • About number 3, how do I pass the value back and forth from usercontrol page to mainpage?

    Monday, October 21, 2013 1:37 PM
  • Just thinking out loud... the usercontrolpage has a public property which stores the length of the leg, which the mainpage can reference.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, October 21, 2013 1:48 PM
    Moderator
  • And thats what I am confused about.  I am referencing the usercontrol many times and input many data.  How will the mainpage know which is which?
    Monday, October 21, 2013 4:21 PM
  • Keep a list of usercontrols that you add.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, October 22, 2013 12:42 PM
    Moderator
  • Keep a list of usercontrols that you add.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Forgive me for not getting back to you earlier.  I've been working about 13 hours a day for my day job. 

    Can you please at least link me to this "list of usercontrols" you are talking about?  I have no idea what this is.

    Saturday, October 26, 2013 5:09 PM
  • Something like this:

    // In the UserControl
    Public List<Leg> MyListOfAllLegs= new List<Leg>();

    Public void AddNewLegToTable (int LegLength, Table TableWhichToAddLeg)

    {
        Leg NewLeg = new Leg(LegLength);
        TableToWhichAddLeg.AddNewLeg(NewLeg, Table.FrontLeftLeg);
        MyListOfAllLegs.Add(NewLeg);

    }

    // IN the MainPage
    Public int TotalLengthOfLegs ()
    {
          int TotalLength = 0;
          foreach (Leg L in UserControl.ListOfAllLegs)
          {
              TotalLength += L.Length;
           }
           Return TotalLength;

    }


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, November 4, 2013 1:47 PM
    Moderator