2011-09-16 63 views
0

什麼我有是包含一個Page類:Silverlight的網頁內容大小

<navigation:Page (...) Title="Import"> 
<Grid x:Name="LayoutRoot"> 
    <ScrollViewer VerticalScrollBarVisibility="Auto" 
        HorizontalScrollBarVisibility="Auto" 
        Visibility="{Binding Visible}"> 
     <c:BusyIndicator IsBusy="{Binding Busy}"> 
      <StackPanel> 
       <StackPanel> 
        <Button/> 
       </StackPanel> 
       <Border Background="#c8c8c8" CornerRadius="5"> 
        <sdk:DataGrid Name="myDataGrid" AutoGenerateColumns="False" 
            ItemsSource="{Binding Imports}" Margin="10" IsReadOnly="True"> 
         <sdk:DataGrid.Columns> 
          <sdk:DataGridTextColumn Header="ID" Binding="{Binding ID}" Width=".3*"/> 
          <sdk:DataGridTextColumn Header="Name" Binding="{Binding Name}" Width=".7*"/> 
         </sdk:DataGrid.Columns> 
        </sdk:DataGrid> 
       </Border> 
      </StackPanel> 
     </c:BusyIndicator> 
    </ScrollViewer>   
</Grid> 
</navigation:Page> 

我試圖做到的是,DataGird總會有最大可能的寬度和高度。它也應該有最小的寬度和高度固定。當瀏覽器比DataGrid小時,ScrollViewer應該啓用滾動。我認爲最小/最大寬度/高度屬性將允許這種行爲,但我無法得到它的工作。

回答

0

需要更改標記一個litle。

StackPanel增長到其整個內容並阻止滾動條顯示。 如果在Grid.Row中設置了一個值,則網格元素重疊內容。當您將busyindicator設置爲高於內容時,它非常有用。

<navigation:Page xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" x:Class="SilverlightApplication1.Page1" 
     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:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation" 
      xmlns:Controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit" d:DesignWidth="640" d:DesignHeight="480" 
     Title="Page1 Page"> 
<Grid x:Name="LayoutRoot"> 
    <Grid.RowDefinitions> 
     <RowDefinition MinHeight="150"/> 
    </Grid.RowDefinitions> 
    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="40"/> 
      <RowDefinition Height="*"/> 
     </Grid.RowDefinitions> 
     <Button Grid.Row="0"/> 
     <Border Grid.Row="1" Background="#c8c8c8" CornerRadius="5"> 
      <sdk:DataGrid Name="myDataGrid" AutoGenerateColumns="False" 
            ItemsSource="{Binding Imports}" Margin="10" IsReadOnly="True"> 
       <sdk:DataGrid.Columns> 
        <sdk:DataGridTextColumn Header="ID" Binding="{Binding ID}" Width=".3*"/> 
        <sdk:DataGridTextColumn Header="Name" Binding="{Binding Name}" Width=".7*"/> 
       </sdk:DataGrid.Columns> 
      </sdk:DataGrid> 
     </Border> 
    </Grid> 
    <Controls:BusyIndicator IsBusy="{Binding Busy}" VerticalAlignment="Center" HorizontalAlignment="Center" /> 
</Grid></navigation:Page>