簡體   English   中英

在這種情況下如何保持網格的縱橫比?

[英]How to maintain the aspect ratio of Grid in this case?

我正在研究silverligth 5,並且在網格中有3行的情況下。 frst包含一些文本,第二個包含Scrollviewer,第三個包含按鈕。

我想要這樣的東西,當我調整網格大小(假設使其更小)時,按鈕(第3行)必須保留,但是scrollviewer(row2)內部的數據可以變小(scrollviewer可以進一步查看),而UIelement首先行還必須像按鈕一樣持久。

這是我的代碼嘗試:

<Grid x:Name="LayoutRoot" Background="{StaticResource BGBrush_1}">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>



    <TextBlock Grid.Row="0" Text="EOD" FontWeight="Bold" Foreground="Orange" Margin="10" VerticalAlignment="Center" />

    <ScrollViewer x:Name="panelScrollViewer" Grid.Row="1" VerticalScrollBarVisibility="Hidden" Height="600">
        <telerik:RadTreeView Name="RadTreeViewObj" VerticalAlignment="Center" Margin="50" Background="{StaticResource BGBrush_1}" BorderBrush="{StaticResource BGBrush_1}" ItemsSource="{Binding EODDataStepsCollection}" SelectionMode="Single" ItemContainerStyle="{StaticResource TreeViewItemStyle}">
            <telerik:RadTreeView.ItemTemplate>
                <telerik:HierarchicalDataTemplate ItemsSource="{Binding RelatedItems}">
                    // here are some UI elements
                </telerik:HierarchicalDataTemplate>
            </telerik:RadTreeView.ItemTemplate>
        </telerik:RadTreeView>
    </ScrollViewer>

    <Grid Grid.Row="2">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Button Grid.Column="0" x:Name="CancelButton" Content="Cancel" FontWeight="Bold" Command="{Binding ButtonCancelCommand}" Height="23" HorizontalAlignment="Left" Margin="30,10,10,10" Style="{StaticResource ButtonStyle_Blue}" VerticalAlignment="Bottom" Width="80" Visibility="{Binding IsValidateVisible, Converter={StaticResource BooleanToVisibilityConverter}}" />
        <Button Grid.Column="1" x:Name="ValidateButton" Content="Validate" FontWeight="Bold" Command="{Binding ButtonValidateCommand}" Height="23" HorizontalAlignment="Right" Margin="10,10,30,10" Style="{StaticResource ButtonStyle_Blue}" VerticalAlignment="Bottom" Width="80" Visibility="{Binding IsValidateVisible, Converter={StaticResource BooleanToVisibilityConverter}}" />
    </Grid>
</Grid>

如何實現呢?

請查看第二個按鈕隱藏在后面。 (只有一半可見)。 如何解決呢?

將行定義更改為此:

<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />

然后從ScrollViewer中刪除固定的Height

第一行和最后一行將盡可能小,而中間行將占用剩余空間。

為避免按鈕重疊,可以按如下所示放置它們:

<StackPanel Grid.Row="2" HorizontalAlignment="Right" Orientation="Horizontal">
        <Button x:Name="ValidateButton" Content="Validate" FontWeight="Bold" Margin="10,10,30,10" VerticalAlignment="Bottom" Width="80"/>
        <Button x:Name="CancelButton" Content="Cancel" FontWeight="Bold" Margin="30,10,10,10"  VerticalAlignment="Bottom" Width="80" />
</StackPanel>

注意:這將使“取消”按鈕右對齊。 (我還將其放在“驗證”按鈕的右側)

暫無
暫無

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

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