.NET 4的WPF的DataGrid MVVM如何把重點放在新行單元格中的WPF的DataGrid
用戶單擊Add按鈕觸發的視圖模型的命令。在viewmodel命令execute中,我將一個新對象添加到網格綁定的視圖模型的viewcollection中。新行出現在我的網格中。不過,我也希望將焦點發送到新行中的第一個可編輯單元格。
我甚至「騙」 MVVM,加在我的視圖模型,視圖聽,知道什麼時候把重點放在新行的事件。
我已經搜查,但沒有運氣。我希望,當我遇到這個傳來:
Datagrid Set focus on newly added row
導致
http://social.msdn.microsoft.com/forums/en-US/wpf/thread/63974f4f-d9ee-45af-8499-42f29cbc22ae
但是,其他人報告這個問題,沒有人回答的是如何應對虛擬化行爲的網格。新添加的行尚未創建。因此,GetCells調用經常失敗。如果ScrollIntoView是必需的,那麼它更有可能失敗。
我已經迷上一噸的事件,包括LoadingRow和RequestBringIntoView沒有運氣的。根據我掛鉤的事件,我設法能夠獲得對單元格的引用。但後來我收到一個錯誤:「內容生成過程中無法調用StartAt」。但是當我調用單元格的BeginEdit時,我檢查了ItemContainerGenerator的狀態,並且它是ContainersGenerated。
???你甚至讀過我的問題嗎?我已經包含了一個指向該頁面的鏈接,GetCell的問題是,如果單元格還沒有創建,它就無法工作。 – happyfirst 2012-02-28 00:36:47
嘗試ScrollIntoView – 2012-02-28 14:06:32
這一工程之前調用dg.UpdateLayout()!!!!早些時候,我發現一個修復,我不得不「調度」一個函數調用,優先級正常,並且工作。但到目前爲止,在ScrollIntoView之前調用UpdateLayout似乎是可靠的。謝謝! – happyfirst 2012-02-29 00:48:07