2014-07-15 66 views
0

目前使用Xamarin.Forms.Labs庫,當我使用的ImageButton,只有文本顯示,而不是圖像:Xamarin窗體的ImageButton

var bttn = new ImageButton { 
       BackgroundColor = Xamarin.Forms.Color.Transparent, 
       Text = "Button", 
       HorizontalOptions = LayoutOptions.FillAndExpand, 
       Source = "image.png", 
       Orientation = Xamarin.Forms.Labs.Enums.ImageOrientation.ImageToLeft, 
       ImageHeightRequest = 50, 
       ImageWidthRequest = 50, 
       WidthRequest = 150, 
       HeightRequest = 150, 
      }; 

爲什麼不顯示圖像?

回答

2

我遇到過這個問題,它讓我瘋狂!這是你如何去解決它。讓我知道這是否有助於你。

iOS:確保您在AppDelegate.cs文件中添加了必要的實施。只需更換你目前有以下內容,請確保您使用 Xamarin.Forms.Labs.iOS

`public partial class AppDelegate : XFormsApplicationDelegate` 

的Android:請確保您的MainActivity.cs文件中添加必要的執行。只需更換你目前有以下內容,確保您使用 Xamarin.Forms.Labs.Droid

`public class MainActivity : XFormsApplicationDroid` 
1

如果資源圖像命名my_image.png那麼你可以使用屬性圖像=「my_image 「:

var leftMenuButton = new Xamarin.Forms.Labs.Controls.ImageButton 
{ 
    Image="my_image", 
    ImageHeightRequest = 10, 
    BackgroundColor = Color.Transparent, 
    BorderColor = Color.Black 
};