调整Scrollviewer和StackPanel WPF C#的大小

时间:2014-10-01 18:05:20

标签: c# wpf scrollviewer

如何让scrollviewer调整大小到屏幕的下边缘,以便最大限度地用鼠标调整大小?代码的方式是,当屏幕最大化时,滚动条不会出现,也无法滚动内容。

我的xaml文件

 <Window x:Class="AppSearch.MainWindow" x:Name="mainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="AppSearch" Height="600" Width="820"
    WindowStartupLocation="CenterScreen" 
    Loaded="Window_Loaded"
    StateChanged="mainWindow_StateChanged"
    ResizeMode="CanResize"
    PreviewKeyDown="mainWindow_PreviewKeyDown">

<Grid ShowGridLines="False">

    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="auto"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <StackPanel x:Name="stkContentLeft" 
                MinWidth="510"
                MinHeight="560"
                ScrollViewer.VerticalScrollBarVisibility="Hidden" 
                LoadCompleted="stkContentLeft_LoadCompleted"
                VerticalAlignment="Stretch"
                HorizontalAlignment="Stretch"
                Margin="0,0,05,0" Grid.Column="0"/>

    <StackPanel Grid.Column="1" x:Name="stckContentRight" Width="276" 
                Height="{Binding Parent.ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}" 
                Orientation="Vertical" 
                HorizontalAlignment="Right">

        <Grid VerticalAlignment="Top">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto"/>
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
            </Grid.RowDefinitions>

            <StackPanel Height="auto" Grid.Row="0">

                <StackPanel x:Name="help" Width="20" Height="20" HorizontalAlignment="Right" Margin="0,5,10,0">
                    <Image Source="Imagens/help_icon.png"/>
                </StackPanel>
                <StackPanel x:Name="stkUcSupervisor" Height="50" Width="276" Margin="0,5,0,0" HorizontalAlignment="Center"/>
                <TextBox x:Name="txtSearch"
                        ToolTip="put your key..." 
                        FontSize="13" 
                        Foreground="Black" 
                        BorderThickness="1" 
                        TextWrapping="Wrap"
                        Margin="0,5,0,05" Width="270" HorizontalAlignment="Center"/>
            </StackPanel>

            <ScrollViewer  x:Name="scroll"
                           CanContentScroll="True" 
                           IsDeferredScrollingEnabled="False" 
                           UseLayoutRounding="False"
                           VerticalScrollBarVisibility="Visible"
                           VerticalAlignment="Top"
                           BorderThickness="1"
                           BorderBrush="Gray"
                           Margin="0,05,0,0"
                           Grid.Row="1" 
                           Height="455">

                    <StackPanel x:Name="stkListOfUserControls" 
                            CanVerticallyScroll="True" 
                            Height="455"
                            OverridesDefaultStyle="False">

                        <StackPanel.ScrollOwner>
                            <ScrollViewer AllowDrop="True" />
                        </StackPanel.ScrollOwner>

                    </StackPanel>

                </ScrollViewer>

        </Grid>

        </StackPanel>
    <StackPanel x:Name="stkPopUp" 
                    Canvas.Bottom="0"
                    Canvas.Left="0"
                    Height="285" 
                    Width="280" 
                    VerticalAlignment="Bottom"/>
</Grid>

0 个答案:

没有答案