我的棱鏡應用程序有很多從我的視圖模型調用的異步操作。 在某些情況下,我希望禁用視圖並顯示某種忙指示符,直到視圖模型從異步操作獲取結果爲止。使用棱鏡創建基礎加載視圖
我雖然創建了一個基本視圖來實現這種行爲(即有一個IsLoading的依賴屬性,它將禁用視圖並在其上方顯示一個忙指示符)。 問題是,我不知道如何實現這個基本視圖。 任何幫助,將不勝感激,謝謝。
編輯:我寫了一個LoadingView,這個工作,我想。
public class LoadingView : UserControl { private object content;
public bool IsLoading
{
get
{
return (bool)GetValue(IsLoadingProperty);
}
set
{
SetValue(IsLoadingProperty, value);
}
}
private ProgressRing m_RingControl;
public LoadingView()
{
m_RingControl = new ProgressRing();
m_RingControl.IsActive = false;
}
// Using a DependencyProperty as the backing store for IsLoading. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsLoadingProperty =
DependencyProperty.Register("IsLoading", typeof(bool), typeof(LoadingView), new PropertyMetadata(false, IsActivePropertyChanged));
private static void IsActivePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
LoadingView view = d as LoadingView;
if (view != null)
{
// Loading - show ring control
if (((bool)e.NewValue) == true)
{
view.content = view.Content;
view.Content = view.m_RingControl;
view.m_RingControl.IsActive = true;
}
else
{
view.m_RingControl.IsActive = false;
view.Content = view.content;
}
}
}
}
,我把在視圖模型
謝謝你的回答,但是我的意圖比viewmodel更關注視圖。 – user2853648
@ user2853648我意識到這一點,我的答案旨在幫助您將一堆異步方法的結果編組爲一個「IsBusy」屬性。如果您仍然在尋找控件,請嘗試[BusyIndicator](http://elegantcode.com/2011/10/07/extended-wpf-toolkitusing-the-busyindicator/) – slugster