Http 下載資料,可背景執行
ref: http://www.loganedge.tw/2017/07/xamarinforms-2listview-interactivity.html
StudentBody studentBody;
var uri = "http://xamarin.github.io/xamarin-forms-book-samples/SchoolOfFineArt/students.xml";
var request = WebRequest.CreateHttp(uri);
//此動作會在背景執行下載任務
request.BeginGetResponse((arg) =>
{
// 反序列 XML
var stream = request.EndGetResponse(arg).GetResponseStream();
var reader = new StreamReader(stream);
var xml = new XmlSerializer(typeof(StudentBody));
studentBody = xml.Deserialize(reader) as StudentBody;
},null);
當App重新啟動時,儲存值還給Editor
ref: http://www.loganedge.tw/2017/05/xamarinforms-entry-editor.html
當 App 關閉時,我們會將 Editor 內的文字存到 Application Properties 內,而當 App 重新啟動時會將儲存的值還給 Editor
App.xaml.cs
protected override void OnSleep()
{
// Handle when your app sleeps
// 執行 JustNote 頁面上的 OnSleep 事件
((JustNotesPage)(((NavigationPage)MainPage).CurrentPage)).OnSleep();
}
[ClassName].xaml.cs
// 取出儲存的值
IDictionary properties = Application.Current.Properties;
if (properties.ContainsKey("text"))
{
editor.Text = (string)properties["text"];
}
public void OnSleep()
{
// 儲存 Editor 的值
Application.Current.Properties["text"] = editor.Text;
}
從網址或內嵌資源載入圖片
ref:http://www.loganedge.tw/2017/04/xamarinforms-bitmaps-image.html
Content = new Image
{
Source = "https://developer.xamarin.com/demo/IMG_1415.JPG"
};
CachingEnabled - 是否使用快取,預設為 True
CachingValidity - 快取保留時間,類別為 TimeSpan,預設是一天
非同步讀取 Uri 圖片
ref:http://www.loganedge.tw/2017/04/xamarinforms-1-uri.html
ActivityIndicator 這 Visual Element,屬性 IsRunning 預設值是 False,所以預設是隱藏的 。
若將 IsRunning 設為 True 就會顯示 轉圈圈的的等待圖 ,每個平台都有預設這個物件和方法,但若你知道程式 執行的時間