2013-10-25 50 views
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 
     } 
    } 
    //... 
} 
+2

你不需要第一個「if」。放下它,看看會發生什麼。 –

+0

我實際上使用if語句來確保如果新索引與currentLocation相同,我不'更新'該值。但是,我試圖刪除if語句(和返回語句),它仍然沒有改變任何東西。 –

+0

@EthanShafer通常你應該在屬性設置器 –

回答

2

根據你在評論中的回答,我們看到你在setter中沒有任何斷點,但試圖使用F11(step into)到達那裏。在禁用相應的調試器設置之前,它將不起作用。打開工具 - >選項 - >調試。查找選項「跳過屬性和操作符」(應該默認啓用)並禁用它。或者在setter中設置斷點,如果更方便的話。