문제

스크롤 뷰어 내의 내용이 크기가 높아지고 스크롤 뷰어가 수평 스크롤 막대가 표시되는 이상한 문제가 있습니다. 그러나 ScrollViewer가있는 그리드는 궁극적으로 스크롤 막대를 표시하기에 충분히 크기를 조정하지 않는 것 같습니다.

이 샘플 앱에서 문제를 격리했습니다. 기본적으로 일부 XAML 및 일부 코드는 콘텐츠 크기 증가를 시뮬레이션합니다.

크기 조정 버튼을 클릭 할 때 오른쪽 스크롤 막대가 어떻게 올바르게 표시되지 않는지 주목하십시오. 패딩을 추가하여 올바른 위치에 있지 않음을 보여줍니다.

상단 행을 제거하면 작동하는 것 같습니다.

미리 남자와 여자에 대한 아이디어와 감사가 있습니까?

<UserControl x:Class="SilverlightApplication7.MainPage"
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"
>
<Grid 
    ShowGridLines="True" 
    HorizontalAlignment="Stretch" 
    VerticalAlignment="Stretch"
>
    <Grid.RowDefinitions>
        <RowDefinition x:Name="DealHeaderRow" Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition x:Name="DealBarColumn" Width="Auto"></ColumnDefinition>
        <ColumnDefinition x:Name="MarketViewerColumn" Width="Auto"></ColumnDefinition>
        <ColumnDefinition x:Name="DealEditorColumn" Width="*" ></ColumnDefinition>
        <ColumnDefinition x:Name="InfoColumn" Width="Auto"></ColumnDefinition>
    </Grid.ColumnDefinitions>

    <ContentControl 
        x:Name="DealBarRegionContentControl"
        Grid.Row="0"
        Grid.Column="0" 
        Grid.RowSpan="2"
        VerticalContentAlignment="Stretch"
        HorizontalAlignment="Stretch"
        Margin="0">
        <TextBlock Text="DealBarRegion" Width="150" />
    </ContentControl>

    <ContentControl 
        Grid.Row="0"
        Grid.Column="1" 
        Grid.RowSpan="2"
        VerticalContentAlignment="Stretch"
        HorizontalAlignment="Stretch"
        HorizontalContentAlignment="Stretch">
        <Border Background="#FF9AF172">
            <TextBlock Text="MarketViewerRegion"  Width="150"  />
        </Border>
    </ContentControl>

    <ContentControl 
        Grid.Column="2" 
        Grid.ColumnSpan="2"
        Grid.Row="0"
        HorizontalAlignment="Stretch"
        HorizontalContentAlignment="Stretch" >
        <Border Background="#FFC1FC9F">
            <TextBlock Text="DealHeaderRegion"  />
        </Border>
    </ContentControl>

    <ContentControl 
        Grid.Column="2" 
        Grid.Row="1" 
        VerticalAlignment="Top"
        HorizontalContentAlignment="Stretch" 
        VerticalContentAlignment="Stretch">
        <Border Background="MistyRose" >
            <TextBlock Text="DealEditorRegion" />
        </Border>
    </ContentControl>

    <Grid
        Grid.Column="3" 
        Grid.Row="1" 
    >
        <ContentControl 
            x:Name="InfoRegionControl" 
            VerticalContentAlignment="Stretch"
            HorizontalAlignment="Stretch">
            <!-- without the padding here you can't see the scroll bar at all !! Its like the 
            scroll ScrollViewer isn't correctly calculating its width to include the scroll bar,
            or the grid isn't sizing at the points its visible??-->
            <Border Padding="0,0,9,0" MinWidth="200" x:Name="DealInfoControlPlaceHolder">
                <ScrollViewer  
                    HorizontalAlignment="Stretch" 
                    HorizontalContentAlignment="Stretch"
                    VerticalScrollBarVisibility="Auto" 
                    HorizontalScrollBarVisibility="Auto"  
                    >
                    <StackPanel x:Name="ScrollContentPlaceHolder">
                        <Button Click="Button_Click" Content="Rezize Column" x:Name="ResizeButton" />
                    </StackPanel>
                </ScrollViewer>
            </Border>
        </ContentControl>
    </Grid>
</Grid>

그리고 다음은 다음에 다음과 같습니다.

using System.Windows;
using System.Windows.Controls;

namespace SilverlightApplication7
{
    public partial class MainPage : UserControl
    {
        double _dealInfoControlPlaceHolderHeight = 0;
        double _dealInfoControlPlaceHolderWidth = 0;

        public MainPage()
        {
            InitializeComponent();

            Loaded += (o, e) =>
            {
                // cache the original width and height
                _dealInfoControlPlaceHolderHeight = DealInfoControlPlaceHolder.Height;
                _dealInfoControlPlaceHolderWidth = DealInfoControlPlaceHolder.Width;
            };
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (ScrollContentPlaceHolder.Height == 1200)
            {
                ScrollContentPlaceHolder.Height = _dealInfoControlPlaceHolderHeight;
                ScrollContentPlaceHolder.Width = _dealInfoControlPlaceHolderWidth;
            }
            else
            {
                ScrollContentPlaceHolder.Height = 1200;
                ScrollContentPlaceHolder.Width = 250;
            }
        }
    }
}
도움이 되었습니까?

해결책

좋아, 위의 것이 왜 작동하지 않는지 모르겠지만, 해결 방법으로 페이지를 재구성하여 동일하게 동작합니다. 작동합니다 :

<UserControl x:Class="SilverlightApplication7.MainPage"
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"
>
<Grid 
    ShowGridLines="True" 
    HorizontalAlignment="Stretch" 
    VerticalAlignment="Stretch"
>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition x:Name="DealBarColumn" Width="Auto"></ColumnDefinition>
        <ColumnDefinition x:Name="MarketViewerColumn" Width="Auto"></ColumnDefinition>
        <ColumnDefinition x:Name="DealEditorColumn" Width="*" ></ColumnDefinition>
    </Grid.ColumnDefinitions>

    <ContentControl 
        x:Name="DealBarRegionContentControl"
        Grid.Column="0" 
        VerticalContentAlignment="Stretch"
        HorizontalAlignment="Stretch"
        Margin="0">
        <TextBlock Text="DealBarRegion" Width="150" />
    </ContentControl>

    <ContentControl 
        Grid.Column="1" 
        VerticalContentAlignment="Stretch"
        HorizontalAlignment="Stretch"
        HorizontalContentAlignment="Stretch">
        <Border Background="#FF9AF172">
            <TextBlock Text="MarketViewerRegion"  Width="150"  />
        </Border>
    </ContentControl>

    <Grid
        Grid.Column="2" >
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <ContentControl 
            Grid.Row="0"
            HorizontalAlignment="Stretch"
            HorizontalContentAlignment="Stretch" >
            <Border Background="#FFC1FC9F">
                <TextBlock Text="DealHeaderRegion"  />
            </Border>
        </ContentControl>

        <Grid 
            Grid.Row="1"     
            HorizontalAlignment="Stretch"
            VerticalAlignment="Stretch"
            >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"></ColumnDefinition>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <ContentControl 
                Grid.Column="0"
                VerticalAlignment="Top"
                HorizontalContentAlignment="Stretch" 
                VerticalContentAlignment="Stretch">
                <Border Background="MistyRose" >
                    <TextBlock Text="DealEditorRegion" />
                </Border>
            </ContentControl>
            <ContentControl 
                Grid.Column="1"
                x:Name="InfoRegionControl" 
                VerticalContentAlignment="Stretch"
                HorizontalAlignment="Right">
                <!-- without the padding here you can't see the scroll bar at all !! Its like the 
                scroll ScrollViewer isn't correctly calculating its width to include the scroll bar,
                or the grid isn't sizing at the points its visible??-->
                <Border Padding="0,0,9,0" MinWidth="200" x:Name="DealInfoControlPlaceHolder">
                    <ScrollViewer  
                        HorizontalAlignment="Stretch" 
                        HorizontalContentAlignment="Stretch"
                        VerticalScrollBarVisibility="Auto" 
                        HorizontalScrollBarVisibility="Auto"  
                        >
                        <StackPanel x:Name="ScrollContentPlaceHolder">
                            <Button Click="Button_Click" Content="Rezize Column" x:Name="ResizeButton" />
                        </StackPanel>
                    </ScrollViewer>
                </Border>
            </ContentControl>
        </Grid>
    </Grid>
</Grid>

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top