Silverlight with dynamic height

I have a silverlight app that I want to allow size like a regular HTML page. That is, I want the size of the silverlight plugin to expand and shrink in height to accommodate the dynamic data and controls with which I populate the silverlight application. So, let's say I have a page with a grid and a button. The user presses the button and the grid receives a bunch of lines with images making the natural size of the grid higher than the browser window. I would like to have something in place to resize the silverlight plugin to suit the desired mesh size. The following and several other attempts do not work:

// handler in my main page.
 void MainGrid_LayoutUpdated(object sender, EventArgs e)
 {
     HtmlPage.Window.Invoke("setSilverlightSize", this.MainGrid.DesiredSize.Height);
 }

<body style="height:100%;margin:0;">
    <form id="mainForm" runat="server" style="height:100%;">
        <asp:ScriptManager ID="ScriptManager" runat="server"></asp:ScriptManager>
        <div id="SilverlightContainer"  style="height:100%;">
            <asp:Silverlight ID="SLMain" runat="server" Source="~/ClientBin/My.Silverlight.Main.xap" Version="2.0" Width="100%" Height="100%" />
        </div>
    </form>
    <script type="text/javascript">
        function setSilverlightSize(val) {
            var host = document.getElementById("SilverlightContainer");
            host.style.height = val + "px";
        }
    </script>
</body>

Desired size MainGrid always wants to be the size of the window. Arg told the pirate.

-r

+5
4
  • ""
  • "no"
  • "0"
  • div "100%"
  • Silverlight "100%"

. HTML.

:

<style type="text/css"> 
html, body { overflow:auto } 
</style>
<head>
    <title>My App</title>
</head>
<body id="bodyId" style="margin:0;" scroll="no">
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
         <div style="position: fixed; height: 100%; width: 100%">
            <avn:Silverlight 
                ID="xamlHost" 
                runat="server" 
                Source="~/ClientBin/THE.xap" 
                MinimumVersion="x.x.xxxxx" 
                Width="100%" 
                Height="100%" 
                />
         </div>
    </form>
</body>
</html>
+2

, , . "ed".

private void LayoutRoot_LayoutUpdated(object sender, System.EventArgs e)
{
    // Set the size of the SL object to the new rendered size of the Grid.
    ResizeSilverlightOnject(this.LayoutRoot.RenderSize.Height);
}

private void ResizeSilverlightObject( double height )
{
    HtmlPage.Window.Invoke( "ResizeObject", new object[] { height } );
}
+1

, javascript HTML-:

/*
When Silverlight is loaded attach silverlight events
*/
function OnSilverlightLoaded(sender, args) {
    //Getting Silverlight object on page
    _silverlightControlHost = document.getElementById("SilverlightObject");
    //Subscribe to it events
    _silverlightControlHost.Content.SilverlightApp.SetHeightEvent = SetHeightEvent;
}

Silverlight:

[ScriptableType]
public partial class MainPage
{
    //Register the event to be as accessible from script
    [ScriptableMember]
    public event EventHandler<HeightEventHandler> SetHeightEvent;

    public MainPage()
    {
        InitializeComponent();

        //Register this instance to be accessible from script
        HtmlPage.RegisterScriptableObject("SilverlightApp", this);
    }

    public void SomeMethod()
    {
        if (this.SetHeightEvent != null)
            this.SetHeightEvent(this, new HeightEventHandler() { Altura = _heightSilverObj.ToString() });
    }
}

[ScriptableType]
public class HeightEventHandler : EventArgs
{
    public string Altura { get; set; }
}

!

+1

( , ), : Page.xaml.cs // Page_Loaded

void Page_Loaded(object sender, RoutedEventArgs e)
{
        SetupPage();
        this.ValidationSummary.SizeChanged += new SizeChangedEventHandler(ValidationSummary_SizeChanged);
}
void ValidationSummary_SizeChanged(object sender, SizeChangedEventArgs e)
    {
        if (this.OriginalPageHeight == 0.0)
        {
            this.OriginalPageHeight = this.RenderSize.Height;
        }
        else
        {
            double expandSize = this.OriginalPageHeight + e.NewSize.Height;
            ResizeSilverlightObject(expandSize);
        }
    }

EDIT: ​​ Javascript cs

    function ResizeObject(height) {
        var host = document.getElementById("uploaderHost");
        host.style.height = height + "px";
    }

public void ResizeSilverlightObject(double height)
    {
       HtmlPage.HtmlWindow.Invoke("ResizeObject", new object[] { height });

    }
0
source

All Articles