0
因此,我一直在摸索着這一段時間,我無法弄清楚。我經歷了一些調試步驟,看看它掛起的位置,Visual Studio不會給我任何東西。基本上,我有一個類的數組,跟蹤數組和當前圖像的當前索引。公共設置方法不會更新
但是,當我調試(或不調試)時,無論「index」的值是什麼,「currentLocation」都不會更新。我似乎無法弄清楚問題可能是什麼。有什麼建議麼?
public class TestClass : INotifyPropertyChanged
{
//...
public void GoTo(int index)
{
if (index == currentLocation)
return;
else if (index >= data.Length)
this.currentLocation = data.Length - 1;
else if (index <= 0)
this.currentLocation = 0;
else
this.currentLocation = index;
//this is where the debugging drops off
}
//doesn't matter if I initialize the value or not
//private int _currentLocation = 0;
private int _currentLocation;
public int currentLocation
{
get { return _currentLocation; }
set
{
//never hits this line
this.SetProperty(ref this._currentLocation, value);
//more work
}
}
//...
}
你不需要第一個「if」。放下它,看看會發生什麼。 –
我實際上使用if語句來確保如果新索引與currentLocation相同,我不'更新'該值。但是,我試圖刪除if語句(和返回語句),它仍然沒有改變任何東西。 –
@EthanShafer通常你應該在屬性設置器 –