5

通常のHTMLページのようにサイズを変更できるSilverlightアプリがあります。つまり、Silverlightプラグインのサイズを拡大および縮小して、Silverlightアプリに入力する動的データとコントロールに対応する必要があります。つまり、グリッドとボタンのあるページがあるとします。ユーザーがボタンを押すと、グリッドは画像を含む一連の行を取得し、グリッドの自然なサイズをブラウザウィンドウよりも大きくします。グリッドのDesiredSizeに対応するために、Silverlightプラグインのサイズを変更するための何かを用意したいと思います。以下、および他のいくつかの試みは機能していません。

// 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>

MainGridの目的のサイズは、常にウィンドウのサイズである必要があります。アーグは海賊が言った。

-r

4

4 に答える 4

2
  1. オーバーフローを「自動」に設定します
  2. スクロールを「いいえ」に設定します
  3. マージンを「0」に設定します
  4. 含まれる div の幅と高さを「100%」に設定します。
  5. 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>
于 2009-05-11T11:46:28.930 に答える
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; }
}

これは機能しています!

于 2012-07-04T19:55:54.200 に答える
1

私はこれを使用しましたが、うまく機能しているようです。Render"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 } );
}
于 2009-06-21T00:48:45.243 に答える
0

検証の概要を使用して高さを決定しようとしている場合 (この質問とは少し関係ありませんが、便利です)、これを試してください: 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 });

    }
于 2010-03-17T15:39:47.883 に答える