簡體   English   中英

ScrollViewer和Grid的組合無法按預期工作

[英]Combination of ScrollViewer and Grid not working as expected

我定義了以下DialogWindow:

<ui:DialogWindow x:Class="CodeElementRatingWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ui="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.12.0"
        Title="CodeElementRatingWindow" Height="600" Width="800">
    <Grid Name="root">
        <Grid.RowDefinitions>
            <RowDefinition Height="60px"></RowDefinition>
            <RowDefinition Height="510px"></RowDefinition>
            <RowDefinition Height="30px"></RowDefinition>
        </Grid.RowDefinitions>
        <Label Grid.ColumnSpan="2" Grid.Row="0" Grid.Column="0" Name="TitleLabel" Content="Please rate the difficulty you perceived while working with each of the following code elements (1 = ''very easy'' / 6 = ''very difficult'')"></Label>
        <ScrollViewer MinHeight="510px">
            <Grid Grid.ColumnSpan="2" Grid.Row="1" Grid.Column="1" Name="ElementContainer">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                    <ColumnDefinition Width="150"></ColumnDefinition>
                </Grid.ColumnDefinitions>
            </Grid>
        </ScrollViewer>
        <Grid Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"></ColumnDefinition>
                <ColumnDefinition Width="*"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Button Content="OK" Grid.Column="0" Click="OK_Button_Click"></Button>
            <Button Content="Cancel" Grid.Column="1" Click="Cancel_Button_Click"></Button>
        </Grid>
    </Grid>
</ui:DialogWindow>

布局基本上由三行組成。 第一行有一個標題標簽,第二行有兩個按鈕,在中間,我想有一個UI元素列表,該列表是我在代碼中動態添加到網格中的。 由於我事先不知道有多少個項目,因此我想在ScrollViewer中顯示它們。

我可以看到繪制了ScrollViewer,但是問題是ScrollViewer與標題標簽重疊,並且有些笨拙。 當我刪除ScrollViewer時,情況並非如此。 那我在做什么錯?

只需為ScrollViewer更改Grid.Row = 1。 會的。 請參考下面的代碼。

<Grid Name="root">
        <Grid.RowDefinitions>
            <RowDefinition Height="60px"></RowDefinition>
            <RowDefinition Height="510px"></RowDefinition>
            <RowDefinition Height="30px"></RowDefinition>
        </Grid.RowDefinitions>
        <Label Grid.ColumnSpan="2" Grid.Row="0" Grid.Column="0" Name="TitleLabel" Content="Please rate the difficulty you perceived while working with each of the following code elements (1 = ''very easy'' / 6 = ''very difficult'')"></Label>
        <ScrollViewer MinHeight="510px" Grid.ColumnSpan="2" Grid.Row="1" Grid.Column="1">
            <Grid  Name="ElementContainer">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                    <ColumnDefinition Width="150"></ColumnDefinition>
                </Grid.ColumnDefinitions>
            </Grid>
        </ScrollViewer>
        <Grid Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"></ColumnDefinition>
                <ColumnDefinition Width="*"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Button Content="OK" Grid.Column="0" Click="OK_Button_Click"></Button>
            <Button Content="Cancel" Grid.Column="1" Click="Cancel_Button_Click"></Button>
        </Grid>
    </Grid>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM