Moving silverlight HTML object
Last post 07-10-2007 6:03 AM by LordOsh. 2 replies.
Sort Posts:
07-09-2007 7:18 AM
Moving silverlight HTML object

Hi,
I'm having hard time figuring out how to move silverlight object ('the whole plugin') within my HTML page. What I want to do is to move the object after user clicks on it. (Eg. User clicks on the objects, silverlight object moves on position say left: 200px, top: 200px). I tried setting silverlight into the windowless mode and then setting style left&top of a parent div without any success though.  Hope I'm clear.

Thanks in advance,
Ondra Stastny
 

LordOsh

Joined on 07-09-2007
Posts 10
07-09-2007 2:13 PM
Re: Moving silverlight HTML object

I've got a little update. I've just found out that my code works in IE but not Firefox which I used initialy. So I still have to figure out how to make it cross-browser compatibile.

 

HTML code:

<!DOCTYPE html PUBLIC
  "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  <head>
    <title>Test</title>
    <script type="text/javascript" src="Silverlight.js"></script>
   
    <script type="text/javascript">
        function helloworld() {
            var style = document.getElementById("mySilverlightControl").style;
            style.left = '200px';
            style.top = '200px';
           
            alert('test');
        }
    </script>

  </head>
  <body>

    <div id="myTestControl" style="backgroung-color: white; position: absolute; ">
    test
    </div>
   
    <!-- Where the Silverlight control will go-->
    <div id="mySilverlightControl" style="backgroung-color: white; position: absolute; left: 0px">
    </div>
   
    <script type="text/javascript">
        // Retrieve the div element you created in the previous step.
        var parentElement =
            document.getElementById("mySilverlightControl");
       
        Sys.Silverlight.createObject(
        "test.xaml",                  // Source property value.
        parentElement,                  // DOM reference to hosting DIV tag.
        "mySilverlightControl",         // Unique control ID value.
        {                               // Control properties.
            width:'300',                // Width of rectangular region of
                                        // control in pixels.
            height:'300',               // Height of rectangular region of
                                        // control in pixels.
            inplaceInstallPrompt:false, // Determines whether to display
                                        // in-place install prompt if
                                        // invalid version detected.
            background:'#00000000',       // Background color of control.
            isWindowless:'true',       // Determines whether to display control
                                        // in Windowless mode.
            framerate:'24',             // MaxFrameRate property value.
            version:'0.9'               // Control version to use.
        },
        {
            onError:null,               // OnError property value --
                                        // event handler function name.
            onLoad:null                 // OnLoad property value --
                                        // event handler function name.
        },
        null);                          // Context value -- event handler function name.
       
       
    </script>

  </body>
</html>

LordOsh

Joined on 07-09-2007
Posts 10
07-10-2007 6:03 AM
Marked as Answer
Re: Moving silverlight HTML object

Ok, nevermind. I've managed to make it work. This is the solution:

            var div = document.getElementById("mySilverlightControl");
           
            if(document.all)    //IE
            {
                div.style.left = '100px';
                div.style.top = '100px';
            }
            else
            {
                div.setAttribute('style', 'position: absolute; top: 100px; left:100px');
            }

LordOsh

Joined on 07-09-2007
Posts 10