Search code examples
c#javascriptsilverlightsharepointribbon

A Button in the SharePoint ribbon to access Silverlight functions


i'm going to build a Silverlight application which is hosted in a custom web part in an empty SharePoint project. I'm using SharePoint 2010 Silverlight 4 and .net 3.5 .

My task and my problem is to make a custom ribbon on the SharePoint site. In this ribbon is a button who should access a Silverlight method. I have made the ribbon and the button but now I can't go any further.

In my Classic C# Web Part I have the following code:

"<div id='silverlightControlHost' style='width:100%;height:100%;'>" +
                            "<object id='SLP' data='data:application/x-silverlight-2,' type='application/x-silverlight-2' width='100%' height='600'>" +
                                "<param name='source' value='Silverlight_File/BMS_C_M_Silverlight.xap' />" +
                                "<param name='initParams' value='<%= InitParameters %>' />" +
                                "<param name='background' value='white' />" +
                                "<param name='minRuntimeVersion' value='4.0.50401.0' />" +
                                "<param name='autoUpgrade' value='true' />" +
                                "<a href='http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50401.0' style='text-decoration:none'>" +
                                "<img src='http://go.microsoft.com/fwlink/?LinkId=161376' alt='Get Microsoft Silverlight' style='border-style:none'/>" +
                                "</a>" +
                            "</object>"

In my MainPage.xaml.cs in the Mail Method:

HtmlPage.RegisterScriptableObject("CallSilverlightCode", this);

In the same file:

[ScriptableMember]
        public void ShowAlertPopup()
        {

            MessageBox.Show("Message From JavaScript");

        }

And in the elements.xml from the ribbon:

<CommandUIHandler
          Command="CallSilverlight"
          CommandAction="javascript:var SLPlugin = document.getElementById('SLP'); SLPlugin.Content.CallSilverlightCode.ShowAlertPopup();"/>
        </CommandUIHandlers>

With all these things the Button in the ribbon should call the "ShowAlertPopup" Method out of Silverlight Application but i don't do it.

I search everything that shoud helps but i don't find anything. I looked thow many things in the IE Debugger by deploying it and so on...

Can anyone helps ? See a problem or a mistake ?

Thanks for your answers

Bilib


Solution

  • I have got a solution. I made a hole new Project as a Sandbox solution insert the Silverlight App in a aspx Site and follow the steps of the this tutorial

    Tutorial

    It is not a custom ribbon tab but i can access the Silverlight app.