Xamarin XAML語言教程隱藏文件使用Progress屬性設(shè)置進(jìn)度條

Xamarin XAML語言教程隱藏文件使用Progress屬性設(shè)置進(jìn)度條

Xamarin XAML語言教程隱藏文件中使用Progress屬性設(shè)置進(jìn)度條進(jìn)度,開發(fā)者除了可以在XAML中使用Progress屬性設(shè)置進(jìn)度條的當(dāng)前進(jìn)度外,還可以在代碼隱藏文件中使用Progress屬性來設(shè)置進(jìn)度條的當(dāng)前進(jìn)度。這時(shí),首先需要在XAML文件中,使用x:Name屬性為進(jìn)度條定義一個(gè)名稱,然后在代碼隱藏文件中通過定義的名稱對Progress屬性進(jìn)行設(shè)置即可。

【示例12-7:ProgressBarProgressOne】以下將在代碼隱藏文件中實(shí)現(xiàn)對進(jìn)度條當(dāng)前進(jìn)行的設(shè)置。具體的操作步驟如下:

(1)MainPage.xaml文件,編寫代碼,對內(nèi)容頁面進(jìn)行布局。代碼如下:

xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"

xmlns:local="clr-namespace:ProgressBarProgressOne"

x:Class="ProgressBarProgressOne.MainPage">

VerticalOptions="Center">

Clicked="SetProgressPointTwo"/>

Clicked="SetProgressPointSix"/>

Clicked="SetProgressOne"/>

(2)打開MainPage.xaml.cs文件,編寫代碼,實(shí)現(xiàn)通過按鈕控制進(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)度條中顯示對應(yīng)的進(jìn)度,效果類似于圖12.26~12.27所示。


圖12.24? Android的運(yùn)行效果圖12.25iOS的運(yùn)行效果
圖12.26? Android的運(yùn)行效果圖12.27iOS的運(yùn)行效果
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容