我使用Xamarin中稱爲「TableView for a form」的樣本來測試應用程序,並且遇到了一個過時的部分,ImageSource = Device.OnPlatform,現在用switch語句。這裏沒有問題,但有很多信息,我有一個奇怪的問題,不能看到問題。Xamarin.Forms ImageSource = Device.OnPlatform過時
我添加的代碼目前已經在下面的代碼中註釋掉了,並且可以用這種方式編譯,當然沒有圖片。如果我刪除評論部分,則會在第35行中發現錯誤,缺少}。 如果我突出顯示最後一個突破下面的花括號,它會發現它的匹配switch()。如果我突出顯示下面的開放大括號,它認爲它是公共SearchPage()的一部分。 交換機中的某些東西導致問題,但我無法看到它。
我希望有人遇到此問題並可能有答案。讓我知道你是否需要更多細節。
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;
//using static System.Net.Mime.MediaTypeNames;
namespace MiddleMeeter
{
class SearchPage : ContentPage
{
public SearchPage()
{
Label header = new Label
{
Text = "TableView for a form",
FontSize = 30,
FontAttributes = FontAttributes.Bold,
HorizontalOptions = LayoutOptions.Center
};
TableView tableView = new TableView
{
Intent = TableIntent.Form,
Root = new TableRoot("TableView Title")
{
new TableSection("Table Section")
{
new TextCell
{
Text = "Text Cell",
Detail = "With Detail Text",
},
new ImageCell
{
/**********************************************************************************************
switch (Device.RuntimePlatform)
{
case Device.iOS:
ImageSource.FromUri(new Uri("http://xamarin.com/images/index/ide-xamarin-studio.png"));
break;
case Device.Android:
ImageSource.FromFile("waterfront.jpg");
break;
case Device.WinPhone:
ImageSource.FromFile("Images/waterfront.jpg");
break;
default:
ImageSource.FromFile("Images/waterfront.jpg");
break;
},
*///////////////////////////////////////////////////////////////////////////////////////////////
Text = "Image Cell",
Detail = "With Detail Text",
},
new SwitchCell
{
Text = "Switch Cell"
},
new EntryCell
{
Label = "Entry Cell",
Placeholder = "Type text here"
},
new ViewCell
{
View = new Label
{
Text = "A View Cell can be anything you want!"
}
}
},
}
};
// Build the page.
this.Content = new StackLayout
{
Children =
{
header,
tableView
}
};
}
}
}
這正是它所需要的。我希望Xamarin清楚他們的應用程序的變化,但很高興解決了它。謝謝 –