我得到的是一个包含以下内容的Page类:
<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 :(得分:0)
需要更改标记。
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>