1

外側のグリッドを使用して画面を4つの部分に分割するWPFウィンドウを作成したいと思います。右下の象限に、グリッドセルよりも大きい別のグリッドを埋め込みたいと思います。ScrollViewerを追加する(またはGrid.ScrollViewerプロパティを使用する)方法を探していましたが、何を試しても、内側のグリッドのサイズが変更されたり、スクロールバーが適切に表示されたりしません

単に大きくなりすぎる(そして他のグリッドにクリップされる)のではなく、内側のグリッドがスクロールバーを尊重するように強制する適切なサイズ設定(およびサイズ変更)動作で、内側のグリッドを正しいパネルでラップしないことと関係があると思います窓)。

ホスティングウィンドウは次のように定義されます。

<Window x:Class="GridScrollTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:GridScrollTest"
        Title="MainWindow" Height="350" Width="525">
    <Grid x:Name="OuterGrid">
        <Grid.RowDefinitions>
            <RowDefinition Height="100" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <local:SSControl x:Name="Sheet" 
                         Grid.Row="1" Grid.Column="1"
                         HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Yellow" />
        <Canvas Grid.Row="0" Grid.Column="0" Background="LightGreen" />
        <Canvas Grid.Row="1" Grid.Column="0" Background="LightBlue" />
        <Canvas Grid.Row="0" Grid.Column="1" Background="LightCoral" />
    </Grid>
</Window>

そして参照されるSSControl:

<UserControl x:Class="GridScrollTest.SSControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    Height="270" Width="600">
    <ScrollViewer 
        HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
        CanContentScroll="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
        <Grid x:Name="CellGrid" ShowGridLines="False" 
              >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="100" />
                <ColumnDefinition Width="100" />
                <ColumnDefinition Width="100" />
                <ColumnDefinition Width="100" />
                <ColumnDefinition Width="100" />
                <ColumnDefinition Width="100" />
                <ColumnDefinition Width="100" />
                <ColumnDefinition Width="100" />
                <ColumnDefinition Width="100" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="30"  />
                <RowDefinition Height="30"  />
                <RowDefinition Height="30"  />
                <RowDefinition Height="30"  />
                <RowDefinition Height="30"  />
                <RowDefinition Height="30"  />
                <RowDefinition Height="30"  />
                <RowDefinition Height="30"  />
                <RowDefinition Height="30"  />
                <RowDefinition Height="30"  />
                <RowDefinition Height="30"  />
                <RowDefinition Height="30"  />
            </Grid.RowDefinitions>
        </Grid>
    </ScrollViewer>
</UserControl>
4

1 に答える 1

3

確かなことはわかりませんが、Blendでコードを試した後、問題はとをに設定したことである可能性がColumnDefinition.WidthありRowDefinition.HeightますAuto。それらをに設定して、ユーザーコントロールのと*を削除してみてください。このように、外側のグリッドはウィンドウ内の使用可能なすべてのスペースを埋め、右下のセルにはスクロールバーがあります。Height=270Width=600

于 2010-04-27T15:41:38.167 に答える