使用 Silverlight 应用程序填充浏览器窗口

发布于 2024-07-16 08:12:53 字数 1467 浏览 5 评论 0原文

我希望我的 Silverlight 应用程序填满整个浏览器窗口。 我已将插件对象的宽度和高度设置为 100%,并将 LayoutRoot 容器的高度和宽度设置为自动,但仍然没有成功。 有什么建议么?

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <asp:Silverlight ID="Silverlight1" runat="server" 
        Source="~/ClientBin/Client.xap"
        MinimumVersion="2.0.30818.0"
        AutoUpgrade="true"
        Height="100%" 
        Width="100%">
    </asp:Silverlight>
</form>

<UserControl 
    x:Class="Client.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Height="Auto"
    Width="Auto">
    <Grid 
        x:Name="LayoutRoot" 
        Background="#084E85"
        ShowGridLines="True">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="280" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="80" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="600" />
        </Grid.RowDefinitions>

        ...Remaining content here...
    </Grid>
</UserControl>

免责声明:我首先搜索答案,找到这个线程。 但是,正如您所看到的,我的代码对我不起作用。

I want my Silverlight app to fill the entire browser window. I've set the plugin object width and height to 100%, and set my LayoutRoot container's height and width to Auto, but still no luck. Any suggestions?

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <asp:Silverlight ID="Silverlight1" runat="server" 
        Source="~/ClientBin/Client.xap"
        MinimumVersion="2.0.30818.0"
        AutoUpgrade="true"
        Height="100%" 
        Width="100%">
    </asp:Silverlight>
</form>

<UserControl 
    x:Class="Client.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Height="Auto"
    Width="Auto">
    <Grid 
        x:Name="LayoutRoot" 
        Background="#084E85"
        ShowGridLines="True">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="280" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="80" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="600" />
        </Grid.RowDefinitions>

        ...Remaining content here...
    </Grid>
</UserControl>

Disclaimer: I searched for an answer first, finding this thread. However, as you can see by my code that isn't working for me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

怪我入戏太深 2024-07-23 08:12:53

首先,我没有在用户控件中设置高度/宽度。 相反,我设置了 DesignHeight 和 DesignWidth(在“http://schemas.microsoft.com/express/blend/2008”命名空间中),并将对齐方式设置为拉伸

<UserControl ... 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
    d:DesignHeight="1050" d:DesignWidth="1680">

在 HTML 中,我设置像这样将高度和宽度设置为 100%...

<div style="height: 100%; width: 100%; position: fixed;">
        <asp:Silverlight runat="server" Source="~/ClientBin/My.xap" ID="MyId" 
            Width="100%" Height="100%" />
</div>

那时,一切都对我有用,让它占据整个窗口。

First, I don't set the height/width in the user control. Instead, I set the DesignHeight and DesignWidth (in the "http://schemas.microsoft.com/expression/blend/2008" namespace) and I set the alignment to stretch

<UserControl ... 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
    d:DesignHeight="1050" d:DesignWidth="1680">

In my HTML, I set the Height and Width to 100% like this...

<div style="height: 100%; width: 100%; position: fixed;">
        <asp:Silverlight runat="server" Source="~/ClientBin/My.xap" ID="MyId" 
            Width="100%" Height="100%" />
</div>

At that point, everything works for me to have it take the entire window.

皇甫轩 2024-07-23 08:12:53

从“自动高度”和“宽度”中删除“高度”和“宽度”属性,

<UserControl
     x:Class="Client.Page"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

并调整窗口大小以适合内容。 如果删除“高度”和“宽度”属性,您的 Silverlight 应用程序将增大以适合窗口。

Remove the Height and Width attributes from the :

<UserControl
     x:Class="Client.Page"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

Auto Height and Width with resize the window to fit the content. If you remove the Height and Width attributes, your Silverlight Application will grow to fit the window.

陌路黄昏 2024-07-23 08:12:53

嗯,

我认为您的网格设置得尽可能小(没有“星”列或行)。
您可以尝试再添加一个“星”大小的列和行吗?

正如其他人指出的那样,您还需要删除“自动”尺寸,因为它们会根据内容自动调整尺寸。

还可以尝试在页面上设置背景颜色,以便您看到它实际延伸的位置。

Hmm

I'm thinking your Grid is set-up to be as small as possible (no "star" column or row).
Can you try with one more column and row with a "star" size ?

as other have pointed out, you also need to remove the "auto" sizes, since they auto-size to content.

also try to set a background color on the page, so you see where it actually extends.

最佳男配角 2024-07-23 08:12:53

如果您有相当复杂的 HTML 布局并且不能依赖固定定位,那么您可以使用以下命令调整 #silverlightControlHost div 的大小:

private bool _hasResized;

protected override Size ArrangeOverride(Size finalSize)
{
    if (!_hasResized)
    {
        HtmlPage.Document.GetElementById("silverlightControlHost").SetStyleAttribute("height", finalSize.Height.ToString());
        _hasResized = true;
    }

    return base.ArrangeOverride(finalSize);
}

您可以将其放入 MainPage.cs 中,或者如果您有嵌套的UserControls,然后是需要最大高度的控件。 我还使用以下 XAML 和 Visual Studio 提供的默认 HTML,

<UserControl ...
    VerticalAlignment="Stretch"
    Height="Auto"
    Width="Auto">

我还没有在没有这些设置的情况下对其进行测试,据我所知 Auto 是默认设置。

If you've got a fairly complex HTML layout and can't rely on fixed positioning then you can make the #silverlightControlHost div resize using the following:

private bool _hasResized;

protected override Size ArrangeOverride(Size finalSize)
{
    if (!_hasResized)
    {
        HtmlPage.Document.GetElementById("silverlightControlHost").SetStyleAttribute("height", finalSize.Height.ToString());
        _hasResized = true;
    }

    return base.ArrangeOverride(finalSize);
}

You can put this inside MainPage.cs or if you have nested UserControls, then the control that requires the most height. I'm also using the following XAML and the default HTML Visual Studio provides

<UserControl ...
    VerticalAlignment="Stretch"
    Height="Auto"
    Width="Auto">

I haven't tested it without these settings, as far as I know Auto is the default.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文