簡體   English   中英

如何使Silverlight應用程序占用整個瀏覽器的寬度/高度?

[英]How to make a Silverlight app take up the entire browser width/height?

我有一個頁面,它只是一個由ASP托管的Silverlight 4對象。 我希望它占據瀏覽器的整個寬度和高度,但事實並非如此-它太小了,在角落里。 我在哪里可以調整?

我是Silverlight的新手。 謝謝您的幫助。

編輯:這是.xaml:

<UserControl x:Class="ExpenseCalc_SilverLight.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">

    <Grid x:Name="LayoutRoot" Background="White" Height="Auto" Width="Auto">
        <Rectangle Height="441" HorizontalAlignment="Left" Margin="-21,-14,0,0" Name="rectangle1" Stroke="Black" StrokeThickness="1" VerticalAlignment="Top" Width="583" Fill="#FFA86E6E" Opacity="1" />
        <TextBlock Height="114" HorizontalAlignment="Left" Margin="13,14,0,0" Name="textBlock1" Text="Current Expenses" VerticalAlignment="Top" Width="424" FontSize="28" />

        <sdk:DataGrid AutoGenerateColumns="True" Height="78" HorizontalAlignment="Left" Margin="13,60,0,0" Name="CurrentExpensesGrid" VerticalAlignment="Top" Width="494" />

        <TextBlock FontSize="15" Height="114" HorizontalAlignment="Left" Margin="12,158,0,0" Name="textBlock2" Text="Add New" VerticalAlignment="Top" Width="424" />
        <sdk:Label Height="18" HorizontalAlignment="Left" Margin="13,187,0,0" Name="label1" VerticalAlignment="Top" Width="48" Content="Name" />
        <TextBox Text="{Binding Name, Mode=TwoWay}" Height="23" HorizontalAlignment="Left" Margin="13,205,0,0" Name="NameTextBox" VerticalAlignment="Top" Width="74" />
        <sdk:Label Content="Date" Height="18" HorizontalAlignment="Left" Margin="97,187,0,0" Name="label2" VerticalAlignment="Top" Width="48" />
        <sdk:Label Content="Cost" Height="18" HorizontalAlignment="Left" Margin="203,187,0,0" Name="label3" VerticalAlignment="Top" Width="48" />
        <sdk:Label Content="Who paid" Height="18" HorizontalAlignment="Left" Margin="257,187,0,0" Name="label4" VerticalAlignment="Top" Width="63" />

        <TextBox Text="{Binding Cost, Mode=TwoWay, ValidatesOnExceptions=True}" Height="23" HorizontalAlignment="Left" Margin="203,205,0,0" Name="CostTextBox" VerticalAlignment="Top" Width="48" />

        <sdk:Label Content="Who owes" Height="18" HorizontalAlignment="Left" Margin="337,187,0,0" Name="label5" VerticalAlignment="Top" Width="63" />
        <sdk:AutoCompleteBox Height="23" HorizontalAlignment="Left" Margin="337,205,0,0" Name="WhoOwesInput" VerticalAlignment="Top" Width="74" ValueMemberBinding="{Binding}" LostFocus="WhoOwesInput_LostFocus" />
        <sdk:Label Content="Receipt" Height="18" HorizontalAlignment="Left" Margin="417,187,0,0" Name="label6" VerticalAlignment="Top" Width="63" />
        <Button Content="Add" Height="30" HorizontalAlignment="Left" Margin="337,154,0,0" Name="AddButton" VerticalAlignment="Top" Width="155" FontSize="15" Click="AddButton_Click" />
        <sdk:DatePicker Text="{Binding Date, Mode=TwoWay}" Height="23" HorizontalAlignment="Left" Margin="97,205,0,0" Name="datePicker1" VerticalAlignment="Top" Width="100" />
        <ComboBox Height="23" HorizontalAlignment="Left" Margin="257,205,0,0" Name="WhoPaidComboBox" VerticalAlignment="Top" Width="74" />
        <ListBox Height="100" HorizontalAlignment="Left" Margin="337,232,0,0" Name="WhoOwesListBox" VerticalAlignment="Top" Width="74" KeyDown="WhoOwesListBox_KeyDown" />
        <TextBox Height="23" HorizontalAlignment="Left" Margin="418,205,0,0" Name="textBox1" VerticalAlignment="Top" Width="74" />
    </Grid>
</UserControl>

當您創建SL應用程序並選擇創建Web應用程序時,VS模板會創建一個.html文件,該文件完全可以滿足您的需求。 關鍵部分如下

<style type="text/css">
html, body {
    height: 100%;
    overflow: auto;
}
body {
    padding: 0;
    margin: 0;
}
#silverlightControlHost {
    height: 100%;
    text-align:center;
}
</style>

<form> ,控件包裝在<div id="silverlightControlHost">元素中。

我建議您創建一個快速測試應用程序,選擇創建托管Web應用程序的選項,然后從那里獲取標記。

檢查您的用戶控件是否被硬編碼到某個大小

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM