2016-05-03 65 views
2

我想設置我的圖像的高度和寬度,並讓它有一個固定的大小,但如果我收縮容器(框架,堆疊面板,網格等...)圖像收縮與它一起。不過,我會假設設置高度和寬度(WidthRequest,HeightRequest,MinimumHeightRequest,MinimumWidthRequest)會迫使圖像保持設置的大小...但它不/Xamarin Forms固定大小的圖像

我能做些什麼...

+0

你有沒有與圖像的看點屬性來測試有3種不同的方面:AspectFill,AspectFit和填充:更詳細的位置:https://developer.xamarin.com/api/type/Xamarin。 Forms.Aspect/ –

回答

2

試試這個;這將設置圖像的寬度和高度與平臺特定的尺寸,即它將使用dp的android和iOS的點。

<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> 
+0

不幸的是,當您調整頁面大小*(在UWP上最容易測試)時,圖像仍會調整大小。 – user1122052

+0

檢查這個職位https://forums.xamarin.com/discussion/65902/how-doi-i-fix-the-size-of-an-image –

+0

這也不工作,如果你把圖像內的網格 – batmaci