How to send parameters to a getXaml()?


  • Simple question, a have a display block and I want to show the generated Xaml with some user input.

    Let's say I want to return something like: "<TextBlock>Hello" + username + "</TextBlock>


    How do I do that?



    Monday, February 11, 2008 5:50 PM

All replies

  • One way to do it would to give the TextBlock a Name like;
    Code Snippet

    <TextBlock Name="txtMyText"></TextBlock>

    And then have a function which you expose in the block XML that does something like:
    Code Snippet

    YourClass.prototype.setUserName = function(username){
       var rootCanvas = ;//  Would need to look at your code to figure out how to get this, feel free to share the block
       rootCanvase.FindName("txtMyText").Text = username;

    You might want to take a look at the block building guide over at http://www.popflywiki.com/Block%20Building%20Guide.ashx.
    Monday, February 11, 2008 9:45 PM
  • Hey Andy, thanks for your reply.

    What about that example I showed before. Let's say I just want to show "<TextBlock>Hello" + username + "</TextBlock>"? What would I need to set rootCanvas variable with?


    I didn't find anything on the getXaml function in the block building guide.




    Tuesday, February 12, 2008 1:02 PM
  • As far as I'm aware the getXaml() method should return a string of Silverlight Xaml which is then appended onto the root canvas of your display block automatically. (So long as you've remembered to put the initializeBase and registerClass calls in)


    So if you wanted to update a textblock that was on your block, you would need to get a reference to it in your javascript code and then change it's Text value.



    For example...


    First you would make the getXaml() method return a nice looking user interface as a sort of template, by returning a string of xaml:


    Code Snippet

    MyBlock.prototype.getXaml = function()


    return '<TextBlock x:Name="myTextBlock">Hello There!</TextBlock>';



    This would make Popfly place that textblock into the root canvas of your display block.


    Then you would need another method in your javascript to actually set the username from some form of input (maybe from another block):


    Code Snippet

    MyBlock.prototype.setUserName = function(username)

       var tb = this.root.findName("myTextBlock");

       tb.Text = "Hello " + username + "!";



    When you create a silverlight display block, Popfly gives you access to the root canvas in a variable called this.root . You can use that variable to find the textblock that you set up in the template xaml, by calling the FindName() method, passing in the name of the thing you want to find. (In this case we called the textblock, myTextBlock)


    Once you have got a reference to that textblock, you can then change any of its attributes from javascript. In this case we are setting the Text property to be "Hello <username>!" (the username is coming from the parameter to this setUserName method)



    Hope that helps.

    Tuesday, February 19, 2008 2:04 PM