You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.7 KiB
55 lines
1.7 KiB
using System;
|
|
using System.ComponentModel;
|
|
using System.Threading.Tasks;
|
|
using Xamarin.Forms;
|
|
|
|
namespace XamarinApp
|
|
{
|
|
[DesignTimeVisible(false)]
|
|
public partial class MainPage : ContentPage
|
|
{
|
|
private const string baseUrlKey = "baseUrl";
|
|
private string _baseUrl;
|
|
|
|
public MainPage()
|
|
{
|
|
InitializeComponent();
|
|
this.option.Source = ImageSource.FromResource($"{this.GetType().Assembly.GetName().Name}.Images.options.png");
|
|
if (!Application.Current.Properties.ContainsKey(baseUrlKey))
|
|
{
|
|
Application.Current.Properties[baseUrlKey] = "http://49.4.92.112";
|
|
}
|
|
this._baseUrl = Application.Current.Properties[baseUrlKey] as string;
|
|
this.webView.Source = this._baseUrl;
|
|
this.Appearing += MainPage_Appearing;
|
|
}
|
|
|
|
private async void MainPage_Appearing(object sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(this._baseUrl))
|
|
{
|
|
await SetBaseUrl();
|
|
}
|
|
else
|
|
{
|
|
this.webView.Source = this._baseUrl;
|
|
}
|
|
}
|
|
|
|
private async void ImageButton_Clicked(object sender, EventArgs e)
|
|
{
|
|
await SetBaseUrl();
|
|
}
|
|
|
|
private async Task SetBaseUrl()
|
|
{
|
|
var input = await DisplayPromptAsync("服务器", "配置服务器地址", "确定", "取消", this._baseUrl, keyboard: Keyboard.Url, initialValue: this._baseUrl);
|
|
if (!string.IsNullOrEmpty(input))
|
|
{
|
|
Application.Current.Properties[baseUrlKey] = input;
|
|
this._baseUrl = input;
|
|
this.webView.Source = this._baseUrl;
|
|
}
|
|
}
|
|
}
|
|
} |