【问题标题】:Grid With Auto Margin - Windows Phone 8.1 Silverlight带有自动边距的网格 - Windows Phone 8.1 Silverlight
【发布时间】:2015-06-21 08:27:36
【问题描述】:

我有这个 XAML 代码,我希望网格位于第 2 行和第 1-3 列。
现在的问题是,如果我指定网格的边距,它在不同尺寸的设备上看起来不太好,如果我不指定边距,网格就会超出移动屏幕。

如何在布局内保持自动边距和网格

<Grid Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3">
    <Button x:Name="undoButton" 
            Content="undo" 
            Grid.Column="1" Grid.Row="2"
            HorizontalAlignment="Left" 
            Click="undoButton_Click" Height="70" Width="90" 
            FontSize="16" Background="#FF4B9599" />
    <Button x:Name="redoButton" Content="redo" 
            Height="70" 
            Width="90"
            Grid.Column="2" Grid.Row="2"
            HorizontalAlignment="Center"  
            Click="redoButton_Click"  FontSize="16" 
            Background="#FF4B9599"/>
    <Button x:Name="clearButton" 
            Content="clear" 
            HorizontalAlignment="Right" 
            Height="70" Width="90"
            Grid.Column="3" Grid.Row="2"
            FontSize="16"  Background="#FF4B9599" 
            Click="clearButton_Click"/>
</Grid>

下面是行和列的定义:

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

不加边距有格子

【问题讨论】:

  • 不明白你的问题,你能说得更具体点吗。请附上一些图纸以获得预期的结果。
  • @Joseph 请检查屏幕截图,希望清楚
  • Grid 中还有哪些其他元素?
  • 尝试为 undoButton 更改 Horizo​​ntalAlignment="Right" 为 clearButton 更改 Horizo​​ntalAlignment="Left"。

标签: c# wpf xaml silverlight


【解决方案1】:

根据您提供给我们的信息, 解决方案很简单

替换这个:

<Grid.RowDefinitions>
    <RowDefinition Height="90" />
    <RowDefinition Height="Auto"/>
    <RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

用这个:

<Grid.RowDefinitions>
    <RowDefinition Height="*"/>
    <RowDefinition Height="*"/>
    <RowDefinition Height="90" />
</Grid.RowDefinitions>

如果您向我们提供有关所需结果的更多信息以及您希望在第 0 行和第 1 行中放入的其他项目,我们可以为您提供更具体的帮助。

【讨论】:

  • 不,它不起作用。但我感谢您的帮助谢谢:)
  • * , '9*' & '*' 工作。以前我不知道它是如何工作的,但现在我明白了。
【解决方案2】:

我不知道问题出在哪里或在哪里,但这有效

 <RowDefinition Height="Auto" MinHeight="80"/>
 <RowDefinition Height="*"/>
 <RowDefinition Height="Auto" MinHeight="70" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多