【发布时间】:2020-05-15 10:53:18
【问题描述】:
我正在尝试使用 Xamarin.Forms 中的 Grid 制作类似钢琴的布局。看起来不错,但由于当我按下其中一个白色按钮时使用了 RowSpan,它会破坏附近黑色按钮的可见性。 Example pressing button "D" 我试图通过在按下白色按钮时将注意力集中在“损坏的”黑色按钮上来解决这个问题,但它没有解决任何问题。我会很感激任何提示。 这是我的 XAML 的一部分:
<Grid.Resources>
<Style TargetType="Button">
<Setter Property="BackgroundColor" Value="White"/>
<Setter Property="Grid.RowSpan" Value="3"/>
<Setter Property="Grid.Row" Value="0"/>
<Setter Property="Grid.ColumnSpan" Value="3"/>
</Style>
</Grid.Resources>
<!--white buttons-->
<Button x:Name="C" Text="C" Grid.Column="0" Clicked="Button_Clicked"/>
<Button x:Name="D" Text="D" Grid.Column="3" Clicked="Button_Clicked"/>
<Button x:Name="E" Text="E" Grid.Column="6" Clicked="Button_Clicked"/>
<Button x:Name="F" Text="F" Grid.Column="9" Clicked="Button_Clicked"/>
<Button x:Name="G" Text="G" Grid.Column="12" Clicked="Button_Clicked"/>
<Button x:Name="A" Text="A" Grid.Column="15" Clicked="Button_Clicked"/>
<Button x:Name="H" Text="H" Grid.Column="18" Clicked="Button_Clicked"/>
<!--black buttons-->
<Button x:Name="Cis" Text="Cis" BackgroundColor="Black" TextColor="White" Grid.Row="0" Grid.Column="2" Grid.ColumnSpan="2" Grid.RowSpan="1" Clicked="Button_Clicked"/>
<Button x:Name="Dis" Text="Dis" BackgroundColor="Black" TextColor="White" Grid.Row="0" Grid.Column="5" Grid.ColumnSpan="2" Grid.RowSpan="1" Clicked="Button_Clicked"/>
<Button x:Name="Fis" Text="Fis" BackgroundColor="Black" TextColor="White" Grid.Row="0" Grid.Column="11" Grid.ColumnSpan="2" Grid.RowSpan="1" Clicked="Button_Clicked"/>
<Button x:Name="Gis" Text="Gis" BackgroundColor="Black" TextColor="White" Grid.Row="0" Grid.Column="14" Grid.ColumnSpan="2" Grid.RowSpan="1" Clicked="Button_Clicked"/>
<Button x:Name="Ais" Text="Ais" BackgroundColor="Black" TextColor="White" Grid.Row="0" Grid.Column="17" Grid.ColumnSpan="2" Grid.RowSpan="1" Clicked="Button_Clicked"/>
【问题讨论】:
-
我想我会尝试将黑白键分成单独的网格
-
试过了,但是在同一个地方有两个完全相同的网格,我只能弹白键或黑键(取决于后面写的内容)
-
将它们彼此相邻对齐,而不是彼此重叠
标签: xamarin.forms