简体   繁体   English

ImageButton 的源图像奇怪地缩放并在 xamarin 表单预览器 (Xamarin.Forms) 中处于错误位置

[英]ImageButton's source image scales weirdly and goes in a wrong position in xamarin forms previewer (Xamarin.Forms)

I have an ImageButton which will work fine with some properties, but as soon as i add these properties to it CornerRadius , BorderColor and BorderWidth it acts weird and it scales and also goes in a weird spot of the page.我有一个 ImageButton,它可以很好地处理某些属性,但是一旦我将这些属性添加到它CornerRadiusBorderColorBorderWidth它就会表现得很奇怪,它会缩放并进入页面的奇怪位置。

here is the full xaml code:这是完整的 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="1"
            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="2"
            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>

NOTE :笔记 :

The behaviors i said is for the Image that i used in the ImageButton source not the button itself , see the Picture below, and I SHOULD ALSO SAY THAT THIS PROBLEM ONLY SHOWS ON XAMARIN FORMS PREVIEWER :我所说的行为是针对我在 ImageButton 源中使用的图像而不是按钮本身,请参见下图,并且我还应该说这个问题仅在 XAMARIN 表单预览器上显示

在此处输入图片说明

Can anyone tell me the problem with it and how to fix it?谁能告诉我它的问题以及如何解决它?

Thanks for your help in advance.提前感谢您的帮助。

Try changing the Width for the second column to Auto and changing the Vertical and Horizontal Options for CenterAndExpand . 尝试将第二列的Width更改为Auto ,并将CenterAndExpand的Vertical和Horizo​​ntal选项更改。 Hope it helps. 希望能帮助到你。

Yes, it is just the case for Xamarin Previewer, it often has problems. 是的,Xamarin Previewer就是这种情况,它经常有问题。 And we apologize for the inconvenience. 对于由此带来的不便,我们深表歉意。 The xamarin development team is doing their best to address this issue and we are urging them to release the latest version as soon as possible. xamarin开发团队正在尽最大努力解决此问题,我们敦促他们尽快发布最新版本。

Of course, you can also try other alternate tools ,eg LiveXAML and Xamarin live reload . 当然,您也可以尝试其他替代工具,例如LiveXAMLXamarin live reload

For more details, you can check: 有关更多详细信息,您可以检查:

https://www.livexaml.com/ https://www.livexaml.com/

https://marketplace.visualstudio.com/items?itemName=Xamarin.XamarinLiveReload https://marketplace.visualstudio.com/items?itemName=Xamarin.XamarinLiveReload

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM