Silverlight 页面内容大小基于浏览器大小

发布于 2024-12-05 03:31:33 字数 1402 浏览 0 评论 0原文

我得到的是一个 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应该启用滚动。我认为最小/最大宽度/高度属性将允许这种行为,但我无法让它工作。

What i have got is a Page class that contains:

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

What I try to accomplish is that DataGird will always have max possible width and height. It also should have min width and height fixed. When browser is smaller than DataGrid, ScrollViewer should enable srolling. I thought that Min/Max Width/Height properties will allow this behavior but i am not able to get it working.

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

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

发布评论

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

评论(1

生生漫 2024-12-12 03:31:33

需要稍微改变一下标记。

StackPanel 会增长到其全部内容并防止滚动条可见。
如果在 Grid.Row 中设置一个值,网格元素会重叠内容。当您在内容上方设置繁忙指示器时,它很有用。

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

Need change markup a litle.

StackPanel grow to its entire content and prevent scrollbar make visible.
Grid element overlap content if you set one value in Grid.Row. It's useful when you set busyindicator above content.

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