我试图设置图片的高度和宽度并将其固定大小,但是如果我缩小容器(框架、stackpanel、grid等),则图片也会随之缩小。然而,我本以为设置高度和宽度(WidthRequest、HeightRequest、MinimumHeightRequest、MinimumWidthRequest)会强制图片保持设置的大小…但实际上并没有。
我该怎么办...
我该怎么办...
试试这个;它将使用平台特定的尺寸设置图像的宽度和高度,即对于Android使用dp,对于iOS使用points。
<Image IsVisible="true">
<Image.HeightRequest>
<OnIdiom x:TypeArguments="x:Double">
<OnIdiom.Phone>
<OnPlatform x:TypeArguments="x:Double" iOS="72" Android="100" WinPhone="10" />
</OnIdiom.Phone>
<OnIdiom.Tablet>
<OnPlatform x:TypeArguments="x:Double" iOS="212" Android="140" WinPhone="10" />
</OnIdiom.Tablet>
</OnIdiom>
</Image.HeightRequest>
<Image.WidthRequest>
<OnIdiom x:TypeArguments="x:Double">
<OnIdiom.Phone>
<OnPlatform x:TypeArguments="x:Double" iOS="125" Android="150" WinPhone="10" />
</OnIdiom.Phone>
<OnIdiom.Tablet>
<OnPlatform x:TypeArguments="x:Double" iOS="265" Android="190" WinPhone="10" />
</OnIdiom.Tablet>
</OnIdiom>
</Image.WidthRequest>
<Image.Source>
<OnPlatform x:TypeArguments="ImageSource">
<OnPlatform.iOS>
<FileImageSource File="logo.png" />
</OnPlatform.iOS>
<OnPlatform.Android>
<FileImageSource File="logo.png" />
</OnPlatform.Android>
<OnPlatform.WinPhone>
<FileImageSource File="logo.png" />
</OnPlatform.WinPhone>
</OnPlatform>
</Image.Source>
</Image>