一、裝置類是Xamarin重要開發組成部分,下面介紹一下裝置類的主要用法:
//喚醒打電話
Device.OpenUri(new Uri("tel:180xxxxxxxx"));
//打開網頁
Device.OpenUri(new Uri("http://vipstone.cnblogs.com/"));
//判斷目前運作平台
Device.RuntimePlatform => Device.iOS, Device.Android, Device.WinPhone
//裝置類型平闆、手機、桌面
Device.Idiom => TargetIdiom.Phone, TargetIdiom.Tablet, TargetIdiom.Desktop
//計數器延遲執行
Device.StartTimer (new TimeSpan (0, 0, 60), () => {
// do something every 60 seconds
return true; // runs again, or false to stop
});
更多Device相關資訊請通路:
https://developer.xamarin.com/guides/xamarin-forms/platform-features/device/二、第三方彈窗,模态視窗
先看效果圖:

模态視窗git位址:
https://github.com/rotorgames/Rg.Plugins.Popup基本實作核心代碼:
<?xml version="1.0" encoding="utf-8" ?>
<pages:PopupPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ywgoapp.Pages.Upgrade.UpgradePrompt"
xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup">
<StackLayout VerticalOptions="Center" WidthRequest="290" HorizontalOptions="Center" Spacing="0">
<AbsoluteLayout VerticalOptions="Start">
<Image Source="upgrade_bgtop.png" WidthRequest="290" AbsoluteLayout.LayoutFlags="PositionProportional" AbsoluteLayout.LayoutBounds="0,0"></Image>
<Label x:Name="lb_version" Text="版本更新" AbsoluteLayout.LayoutFlags="XProportional" AbsoluteLayout.LayoutBounds="0.5,74" FontSize="16" TextColor="White"></Label>
<Image x:Name="img_close" IsVisible="False" Source="close3.png" HeightRequest="24" WidthRequest="24" AbsoluteLayout.LayoutFlags="XProportional" AbsoluteLayout.LayoutBounds=".96,52">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnCloseTap"></TapGestureRecognizer>
</Image.GestureRecognizers>
</Image>
</AbsoluteLayout>
<ScrollView Padding="30,20" MinimumHeightRequest="160" BackgroundColor="White">
<Label x:Name="lb_content" Text="" FontSize="12"></Label>
</ScrollView>
<StackLayout Padding="50,0,50,10" BackgroundColor="White">
<Button Text="立即更新" BackgroundColor="#4BC1D2" TextColor="White" Clicked="Button_Clicked">
</Button>
</StackLayout>
<StackLayout Spacing="0">
<Image Source="upgrade_bgbottom.png" WidthRequest="290" Aspect="AspectFill"></Image>
</StackLayout>
</StackLayout>
</pages:PopupPage>
調用代碼:
this.Navigation.PushPopupAsync(new UpgradePrompt());
彈窗要注意的點:
1.不想點選任何區域都消失的話,需要重新OnBackgroundClicked事件:return false;
2.手動關閉窗體:PopupNavigation.PopAsync();
Xamarin系列其他推薦
如果本文對你有所幫助,請打賞——1元就足夠感動我:)
聯系郵箱:[email protected]
我的GitHub:
https://github.com/vipstone關注公衆号:
作者:
王磊出處:
http://vipstone.cnblogs.com/本文版權歸作者和部落格園共有,歡迎轉載,請标明出處。