小編給大家分享一下Xamarin XAML語(yǔ)言中如何使用Progress屬性設(shè)置當(dāng)前進(jìn)度,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
Xamarin XAML語(yǔ)言教程使用使用Progress屬性設(shè)置當(dāng)前進(jìn)度
開發(fā)者除了可以在XAML中使用Progress屬性設(shè)置進(jìn)度條的當(dāng)前進(jìn)度外,還可以在代碼隱藏文件中使用Progress屬性來(lái)設(shè)置進(jìn)度條的當(dāng)前進(jìn)度。這時(shí),首先需要在XAML文件中,使用x:Name屬性為進(jìn)度條定義一個(gè)名稱,然后在代碼隱藏文件中通過(guò)定義的名稱對(duì)Progress屬性進(jìn)行設(shè)置即可。
【示例12-7:ProgressBarProgressOne】以下將在代碼隱藏文件中實(shí)現(xiàn)對(duì)進(jìn)度條當(dāng)前進(jìn)行的設(shè)置。具體的操作步驟如下:
(1)MainPage.xaml文件,編寫代碼,對(duì)內(nèi)容頁(yè)面進(jìn)行布局。代碼如下:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:ProgressBarProgressOne"
x:Class="ProgressBarProgressOne.MainPage">
<StackLayout Spacing="55"
VerticalOptions="Center">
<ProgressBar x:Name="progressBar" />
<StackLayout Spacing="10">
<Button Text="20%的進(jìn)度"
Clicked="SetProgressPointTwo"/>
<Button Text="60%的進(jìn)度"
Clicked="SetProgressPointSix"/>
<Button Text="100%的進(jìn)度"
Clicked="SetProgressOne"/>
</StackLayout>
</StackLayout>
</ContentPage>
(2)打開MainPage.xaml.cs文件,編寫代碼,實(shí)現(xiàn)通過(guò)按鈕控制進(jìn)度條當(dāng)前進(jìn)度的功能。代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace ProgressBarProgressOne
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
//將進(jìn)度條當(dāng)前的進(jìn)度設(shè)置為0.2
void SetProgressPointTwo(object sender, EventArgs args)
{
progressBar.Progress = 0.2;
}
//將進(jìn)度條當(dāng)前的進(jìn)度設(shè)置為0.6
void SetProgressPointSix(object sender, EventArgs args)
{
progressBar.Progress = 0.6;
}
//將進(jìn)度條當(dāng)前的進(jìn)度設(shè)置為1
void SetProgressOne(object sender, EventArgs args)
{
progressBar.Progress = 1;
}
}
}
此時(shí)運(yùn)行程序,會(huì)看到如圖12.24~12.25所示的效果。當(dāng)開發(fā)者輕拍某一按鈕后,會(huì)看到進(jìn)度條中顯示對(duì)應(yīng)的進(jìn)度,效果類似于圖12.24~12.25所示。
圖12.24 Android的運(yùn)行效果 圖12.25 iOS的運(yùn)行效果
以上是“Xamarin XAML語(yǔ)言中如何使用Progress屬性設(shè)置當(dāng)前進(jìn)度”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道!
文章題目:XamarinXAML語(yǔ)言中如何使用Progress屬性設(shè)置當(dāng)前進(jìn)度-創(chuàng)新互聯(lián)
URL網(wǎng)址:http://chinadenli.net/article46/dghoeg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、ChatGPT、用戶體驗(yàn)、微信小程序、定制網(wǎng)站、商城網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容