0

雇用主から次のwpfレイアウトが提供されています。複数のネストされたスタックパネルを利用します。メインウィンドウの四隅から一定の距離を置いてスタックパネル内にあるデータグリッドを固定しようとしています。また、親ウィンドウのサイズが原因で一部が非表示になっているデータがグリッドに含まれている場合は常に、スクロールバーが表示されることになっています。スクロールバーは、不要な場合は非表示にする必要があります。


データグリッドとスタックパネルの幅を[自動]に設定して、幅がいっぱいになり、水平スクロールバーと垂直スクロールバーが希望どおりに動作するようにしました。しかし、グリッドには必要な高さがありません。


しかし、データグリッドのheightプロパティを自動に設定しようとすると、水平スクロールバーと垂直スクロールバーの両方が非表示になり、データが非表示になります。データグリッドの高さプロパティを固定サイズに設定し、ウィンドウのサイズが変更されるたびに更新しようとしましたが、スクロールバーがまだ非表示になっていますが、これを修正するにはどうすればよいですか?

<UserControl x:Class="WpfApplication1.UserControl1"
             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" 
             mc:Ignorable="d" 
             d:DesignHeight="441" d:DesignWidth="300">
    <Grid>
        <StackPanel Margin="0" Name="stackPanel1">
            <ListBox Height="100" Name="listBox1" Width="253" />
            <Button Content="Button" Height="23" Name="button1" Width="256" Click="button1_Click" />
            <StackPanel Name="stackPanel2">
                <StackPanel Height="34" Name="stackPanel3" Width="249" />
                <DataGrid AutoGenerateColumns="False" Name="dataGrid1" Height="282" />
            </StackPanel>
        </StackPanel>
    </Grid>
</UserControl>

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:my="clr-namespace:WpfApplication1" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="WpfApplication1.MainWindow"
        Title="MainWindow" Height="502" Width="525" StateChanged="Window_StateChanged">
    <Grid Margin="0">
        <my:UserControl1 x:Name="userControl11" Loaded="userControl11_Loaded" />
    </Grid>
</Window>
4

2 に答える 2

3

あなたがアイテムを垂直に置くとき、StackPanel彼らは彼らが無限の垂直スペースを持っているふりをするのが好きです。の行の指定に切り替えて、それらの行の1つにGrid配置します。DataGrid内部にある場合、Grid使用可能なスペースの量を認識しており、スクロールバーを適切に表示する必要があります。

于 2012-10-31T22:52:06.293 に答える
2

StackPanelのものの中のこのStackPanelのすべてを理解していません。レイアウトには単にグリッドを使用する必要があります。

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <ListBox Grid.Row="0" Height="100" Name="listBox1" Width="253" />
    <Button Grid.Row="1" Content="Button" Height="23" Name="button1" Width="256" />
    <StackPanel Grid.Row="2" Height="34" Name="stackPanel3" Width="249" />
    <DataGrid Grid.Row="3" AutoGenerateColumns="False" Name="dataGrid1" />
</Grid>

また、スペースホルダーとして空のStackPanelを使用するのstackPanel3は厄介なようです。これが、WPF要素のMarginプロパティです。

于 2012-10-31T23:03:16.547 に答える