WPF如何實現(xiàn)簡單的進度條

WPF如何實現(xiàn)簡單的進度條?這個問題可能是我們?nèi)粘W(xué)習(xí)或工作經(jīng)常見到的。希望通過這個問題能讓你收獲頗深。下面是小編給大家?guī)淼膮⒖純?nèi)容,讓我們一起來看看吧!

創(chuàng)新互聯(lián)是一家朝氣蓬勃的網(wǎng)站建設(shè)公司。公司專注于為企業(yè)提供信息化建設(shè)解決方案。從事網(wǎng)站開發(fā),網(wǎng)站制作,網(wǎng)站設(shè)計,網(wǎng)站模板,微信公眾號開發(fā),軟件開發(fā),微信小程序開發(fā),十余年建站對成都混凝土攪拌罐等多個行業(yè),擁有多年的網(wǎng)站設(shè)計經(jīng)驗。

最近做一個項目,看到以前同事寫的進度條效果不錯,所以,拿來簡化了下,不炫,但是項目中還是夠用的。

還是,先來看下調(diào)用以后的效果

WPF如何實現(xiàn)簡單的進度條

1、因為ProgressbBar的Foreground顯示不得不一樣,所以,要有一個參數(shù)去給控件進行設(shè)置,因此定義了一個參數(shù)值ForegroundColor

public int ForegroundColor
{get{return _foregroundColor;
    }set{
        _foregroundColor = value;
        LinearGradientBrush lgb = dictionary["ForegroundColor" + value] as LinearGradientBrush;if (lgb != null)
            proBar.Foreground = txt.Foreground = percent.Foreground = lgb;
    }
}

代碼里有這么一句話“LinearGradientBrush lgb = dictionary["ForegroundColor" + value] as LinearGradientBrush;”是為了方便通過這是這個參數(shù)去樣式文件里取樣式的。

<LinearGradientBrush x:Key="ForegroundColor1" EndPoint="1,0.5" StartPoint="0,0.5"><GradientStop Color="#FFBBF586" Offset="0.5"/><GradientStop Color="#FFD4F9C3" Offset="1"/></LinearGradientBrush><LinearGradientBrush x:Key="ForegroundColor2" EndPoint="1,0.5" StartPoint="0,0.5"><GradientStop Color="#FF5BE26E" Offset="0.5"/><GradientStop Color="#FF8DEC9C" Offset="1"/></LinearGradientBrush><LinearGradientBrush x:Key="ForegroundColor3" EndPoint="1,0.5" StartPoint="0,0.5"><GradientStop Color="#FFB656F2" Offset="0.5"/><GradientStop Color="#FFAE8DFE" Offset="1"/></LinearGradientBrush><LinearGradientBrush x:Key="ForegroundColor4" EndPoint="1,0.5" StartPoint="0,0.5"><GradientStop Color="#FF3AE9E9" Offset="0.5"/><GradientStop Color="#FF8DFDFE" Offset="1"/></LinearGradientBrush>

2、既然是ProgressBar就要有一個進度值,這個值,我們用TextBlock來進行顯示,一定要實現(xiàn)通知接口,這樣,才能保證實時的通知到頁面上。

public string ValueText
{get{return _valueText;
    }set{
        _valueText = value;if (this.PropertyChanged != null)
        {this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("ValueText"));
        }
    }
}

3、啟用一個后臺線程,來不斷的更新進度效果

private void Bgw_DoWork(object sender, DoWorkEventArgs e)
{for (int i = 0; i < BarValue; i++)
    {
        System.Threading.Thread.Sleep(50);
        proBar.Dispatcher.Invoke(new Action(                                     delegate{if (proBar.Value <= BarValue)
            {
                proBar.Value++;
            }
        }));
        ValueText = i + "";
    }
    ValueText = BarValue + "";
}

源碼

感謝各位的閱讀!看完上述內(nèi)容,你們對WPF如何實現(xiàn)簡單的進度條大概了解了嗎?希望文章內(nèi)容對大家有所幫助。如果想了解更多相關(guān)文章內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

分享題目:WPF如何實現(xiàn)簡單的進度條
網(wǎng)站URL:http://muchs.cn/article38/piddsp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗網(wǎng)站內(nèi)鏈、虛擬主機、企業(yè)建站App開發(fā)、關(guān)鍵詞優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)