我正在使用一個調度計時器設置爲每20秒觸發一次,其中我需要通過它在我的視圖模型中進行更新數據綁定文本塊。這是在視圖模型計時器代碼:用戶界面沒有得到更新在Windows Phone 7從計時器方法
public TestViewModel()
{
_dispatcherTimer = new DispatcherTimer();
_dispatcherTimer.Interval = new TimeSpan(0, 0, 20);
_dispatcherTimer.Tick += new EventHandler(_dispatcherTimer_Tick);
_dispatcherTimer.Start();
}
void _dispatcherTimer_Tick(object sender, EventArgs e)
{
if(blah == blah)
{
_dispatcher.BeginInvoke(() =>
{
// DoneEnabled is a boolean property that my
// textblock's IsEnabled property is bound to
DoneEnabled = true;
});
}
}
private bool _doneEnabled;
/// <summary>
/// Gets or sets a value indicating whether [done enabled].
/// </summary>
/// <value>
/// <c>true</c> if [done enabled]; otherwise, <c>false</c>.
/// </value>
public bool DoneEnabled
{
get { return _doneEnabled; }
set
{
_doneEnabled = value;
RaisePropertyChanged("DoneEnabled");
}
}
按鈕被啓用的其他地方,當我試圖通過更新此屬性除了在計時器的事件處理程序在我的視圖模型這麼做。任何想法,如果我在這裏失去一些東西?
謝謝。
UPDATE:
編輯
void _dispatcherTimer_Tick(object sender, EventArgs e)
{
if(blah == blah)
{
// DoneEnabled is a boolean property that my
// textblock's IsEnabled property is bound to
DoneEnabled = true;
}
}
的_dispatcherTimer_Tick方法如下
就像一個魅力!
只是想掩蓋顯而易見的問題:您是否驗證了您的viewmodel已正確連接到您的視圖?你確認你確實設置了文本塊的綁定嗎? – earthling 2012-02-28 00:58:18