locked
Referencing canvas from HTML button with javascript RRS feed

  • Question

  • Hi all,

    How to get a reference to the main canvas from javasript (called from HTML button).

    function Button1_onclick() {
      var control = document.getElementById("agControl1");
      var rootcanvas = control.findName("rootCanvas")
      var xamlFragment = '<TextBlock Canvas.Top="200" Opacity="0" Text="Click for more info" />';
      rootcanvas.children.add(control.createFromXaml(xamlFragment));
    }
     

    I tried this but control.findName is not available.

    Ideas ?

    Thanks

     

    Thursday, February 15, 2007 2:01 PM

Answers

  • Also make sure the original XAML content (content where "rootCanvas" is defined) has already loaded. If you do findname before the content has loaded it won't be found.

    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"

    Thursday, February 15, 2007 10:21 PM

All replies

  • Hi Eric,

    Can you send me the xaml you are using?  Also, are you sure your event handler (Button1_onclick()) is getting fired? 

    --Martha

    Test Lead, WPF/E

    Thursday, February 15, 2007 3:01 PM
  • Make sure that you have the right id for the control. This would be the second parameter that you pass to the new aghost call.

    More information on this can be found here: http://msdn2.microsoft.com/en-us/library/bb188575.aspx

    Thursday, February 15, 2007 5:16 PM
  • Also make sure the original XAML content (content where "rootCanvas" is defined) has already loaded. If you do findname before the content has loaded it won't be found.

    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"

    Thursday, February 15, 2007 10:21 PM
  • that is the control.findName which fails

    Is it really possible to get a reference to canvas from outside of WPF/E control. I  mean when javascript is not called from an WPF/E event ?

    Friday, February 16, 2007 7:54 AM
  • Yes. Here is the answer from another thread:

     It was probably filtered by the forum software. I've posted example here:

    http://blogs.sqlxml.org/wpfe/load/

    Xaml: http://blogs.sqlxml.org/wpfe/load/load.xaml

    JS: http://blogs.sqlxml.org/wpfe/load/load.js

    It does work, so perhaps there is something with your code that is breaking it. If you post your code it would make it a lot easier to figure out.

    Friday, February 16, 2007 8:08 AM