我的工作,其中Repository
對象通過包含modified版本TextBox
的,它支持結合SelectionStart
,SelectionLength
,和VerticalOffset
一個DataTemplate顯示的應用文本框。WPF-問題的在的DataTemplate
的DataTemplate中看起來是這樣的:
<DataTemplate DataType="{x:Type m:Repository}">
<controls:ModdedTextBox
x:Name="textBox" Text="{Binding Text, UpdateSourceTrigger=PropertyChanged}"
BindableSelectionStart="{Binding SelectionStart, UpdateSourceTrigger=PropertyChanged}"
BindableSelectionLength="{Binding SelectionLength, UpdateSourceTrigger=PropertyChanged}"
BindableVerticalOffset="{Binding VerticalOffset, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
的問題是,當我改變當前正在顯示的Repository
;在SelectionStart
,SelectionLength
和VerticalOffset
一切似乎越來越設置爲0,即使在Repository
對象的那些屬性不爲0
我認爲這是在瞬間顯示的文本之前當SelectionStart
發生, SelectionLength
和VerticalOffset
不能大於0.這不僅會將TextBox
的實際屬性設置爲零,還會更新綁定並將Repository
對象的屬性設置爲零。
有什麼辦法可以防止這種情況發生?
- 編輯 -
我不知道是否張貼DL鏈接到項目是一個沒有沒有或沒有SO,但這裏是一個項目的鏈接我創建說明問題我有:http://dl.dropbox.com/u/1520079/RepositoryProblemDemo.zip
當您運行demo-app時,您可以單擊「Switch Repository」按鈕來更改文本框中顯示的存儲庫。如果您查看文本框的右側,當切換到另一個時,當前存儲庫的屬性都將設置爲零。
此演示與我的實際應用程序的區別在於,我的應用程序存儲庫將通過熱鍵切換,而不是按鈕。
您可以發佈有關Bindable ***依賴項屬性如何創建/綁定到基礎選擇屬性的信息嗎? – 2010-10-25 08:57:38
您的綁定是否需要雙向並在PropertyChanged上觸發,或者您是否可以使用OneWay或LostFocus? – 2010-10-25 09:40:03
我鏈接到這個問題:http://stackoverflow.com/questions/1175618/how-to-bind-selectionstart-property-of-text-box/1849539#1849539 – Justin 2010-10-26 00:00:17