C# Xaml-使图像适合帧大小
图像: 我正在尝试拉伸图像(顶部的粉红色形状)以适应绿色边框的宽度。 高度合适,但宽度不够 我已经尝试过的是:C# Xaml-使图像适合帧大小,c#,xamarin,C#,Xamarin,图像: 我正在尝试拉伸图像(顶部的粉红色形状)以适应绿色边框的宽度。 高度合适,但宽度不够 我已经尝试过的是: 使用网格代替框架-同样的问题 将屏幕宽度的宽度请求设置为图像-不影响图像 尝试了AspectFill而不是AspectFit,它扩展了图像的宽度,但剪切了一些图像底部- Xaml代码: <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/
<?xml version="1.0" encoding="utf-8" ?>
<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="mada.Views.MainScrolledPage">
<ContentPage.Content>
<Grid Padding="0" ColumnSpacing="0" RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- Top Frame -->
<StackLayout x:Name="_topFrame" BackgroundColor="Yellow" HorizontalOptions="FillAndExpand">
<Frame Margin="0" Padding="0" HorizontalOptions="FillAndExpand" BackgroundColor="Green">
<Image Source="TopShape.png" x:Name="_topShape" Aspect="AspectFit" HorizontalOptions="FillAndExpand" Margin="0"/>
</Frame>
</StackLayout>
<!-- Main Frame -->
<ScrollView Grid.Row="1">
<StackLayout >
<BoxView BackgroundColor="Blue" HeightRequest="150"/>
<BoxView BackgroundColor="white" HeightRequest="150"/>
<BoxView BackgroundColor="Black" HeightRequest="150"/>
<BoxView BackgroundColor="Green" HeightRequest="150"/>
<BoxView BackgroundColor="Blue" HeightRequest="150"/>
</StackLayout>
</ScrollView>
<!-- Bottom Frame -->
<BoxView x:Name="_bottomFrame" BackgroundColor="Yellow" Grid.Row="2"/>
</Grid>
</ContentPage.Content>
</ContentPage>
您可以简单地使用您可以简单地使用
namespace mada.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MainScrolledPage : ContentPage
{
public MainScrolledPage()
{
InitializeComponent();
//emailIcon.WidthRequest = (App.screenWidth * 8.5) / 100;
_topFrame.HeightRequest = FixedHeight(170);
_bottomFrame.HeightRequest = FixedHeight(110);
//_topShape.HeightRequest = FixedHeight(113);
}
public float FixedHeight(float x)
{
float rate = ((x / 812) * 100);
float result = (App.screenHeight * rate) / 100;
return result;
}
}
}