[英]ImageButton's source image scales weirdly and goes in a wrong position in xamarin forms previewer (Xamarin.Forms)
我有一個 ImageButton,它可以很好地處理某些屬性,但是一旦我將這些屬性添加到它CornerRadius
、 BorderColor
和BorderWidth
它就會表現得很奇怪,它會縮放並進入頁面的奇怪位置。
這是完整的 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>
筆記 :
我所說的行為是針對我在 ImageButton 源中使用的圖像而不是按鈕本身,請參見下圖,並且我還應該說這個問題僅在 XAMARIN 表單預覽器上顯示:
誰能告訴我它的問題以及如何解決它?
提前感謝您的幫助。
嘗試將第二列的Width更改為Auto
,並將CenterAndExpand
的Vertical和Horizontal選項更改。 希望能幫助到你。
是的,Xamarin Previewer就是這種情況,它經常有問題。 對於由此帶來的不便,我們深表歉意。 xamarin開發團隊正在盡最大努力解決此問題,我們敦促他們盡快發布最新版本。
當然,您也可以嘗試其他替代工具,例如LiveXAML
和Xamarin live reload
。
有關更多詳細信息,您可以檢查:
https://marketplace.visualstudio.com/items?itemName=Xamarin.XamarinLiveReload
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.