C# ImageButton未在网格列中居中
我添加了3个按钮,它们都在一个网格中,但我的C# ImageButton未在网格列中居中,c#,xaml,xamarin.forms,C#,Xaml,Xamarin.forms,我添加了3个按钮,它们都在一个网格中,但我的ImageButton没有在我的列中居中: 谁能告诉我这个问题以及如何解决 这是xaml代码: <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:d="http://xamarin.com/schemas/2014/form
ImageButton
没有在我的列中居中:
谁能告诉我这个问题以及如何解决
这是xaml代码:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Accounting.MainPage">
<StackLayout Margin="3">
<Entry
x:Name="NameEntry"
Placeholder="Enter the Fullname"
/>
<Grid Margin="3,-6,3,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button
Margin="0,0,2,0"
VerticalOptions="Center"
x:Name="AddButton"
Text="Add"
HeightRequest="50"
BackgroundColor="#03A9F4"
TextColor="White"
CornerRadius="10"
Grid.Column="0"
Clicked="AddButton_Clicked"
/>
<ImageButton
Source="add.png"
Grid.Column="2"
HorizontalOptions="Center"
VerticalOptions="Center"
WidthRequest="50"
HeightRequest="50"
CornerRadius="50"
/>
<Button
Margin="2,0,0,0"
VerticalOptions="Center"
x:Name="DeleteButton"
Text="Delete"
HeightRequest="50"
BackgroundColor="#f44336"
TextColor="White"
CornerRadius="10"
Grid.Column="3"
Clicked="DeleteButton_Clicked"
/>
</Grid>
<ListView x:Name="WorkersListView" BackgroundColor="#ECEFF1" Margin="2" ItemSelected="WorkersListView_ItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell TextColor="Black" Text="{Binding WorkerName}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
提前感谢您的帮助。原因: 设置网格有三列,但设置了DeleteButtonequals 3的
Grid.Column
解决方案:
可以添加一列网格
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
或者将
ImageButton
的Grid.Column
设置为1,将DeleteButton
设置为2。原因:
设置网格有三列,但设置了DeleteButtonequals 3的Grid.Column
解决方案:
可以添加一列网格
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
或者将
ImageButton
的Grid.Column
设置为1,将DeleteButton
设置为2。发布完整代码,以便我们能更好地帮助您。发布完整代码,以便我们能更好地帮助您。这是一个荒谬的问题:D,谢谢您的帮助,另外,我会在新的问题页上问我的另一个问题。这是一个荒谬的问题:D,谢谢你的帮助,我也会在新的问题页上问我的另一个问题。