How to get rowindex / column of a grid control in silverlight?

這是在國外論壇上看到的一個問題,連結在這邊,測試了一下之後,可以利用下面的方式來抓取;例如做了一個像是下圖的介面

項目的列表是放在Grid容器當中,XAML大致上像是這樣

在點選之後要去抓取被點選項目的相關Index,首先要去Handle Grid的滑鼠點選事件,例如
ContentGrid.MouseLeftButtonDown += new MouseButtonEventHandler(ContentGrid_MouseLeftButtonDown);
之後利用Grid.GetRow來達成,例如
void ContentGrid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            //throw new NotImplementedException();
            int rowindex = Grid.GetRow((FrameworkElement)e.OriginalSource);
        }

留言

這個網誌中的熱門文章

開啟cshtml檔案時,出現『並未將物件參考設定為物件執行個體』的錯誤訊息

無法設定中斷點 尚未載入符號檔

DataGridView欄位計算總合