我有一個itemscontrol
,它綁定到一組對象。LostFocus事件在獲得焦點時觸發
在數據模板中,我綁定了將由所有創建的控件在失去焦點時所使用的操作。
在控件中,有一個文本框,所以如果項目控件ItemSource中有1個項目,則會有2個文本框。
現在,如果文本框1有焦點,並且我單擊除了文本框2之外的某個位置,該動作將執行一次(因爲焦點已丟失)。但是如果我點擊文本框2,該動作會執行兩次。爲什麼?
<ItemsControl Grid.Row="1" Margin="0,5,0,5" ItemsSource="{Binding
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type Window}}, Path=Collection}">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type ct:CollectionItem}">
<cc:TestControl
ValueChangedAction="{Binding
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type Window}}, Path=ValueChangedAction}"
VerticalAlignment="Center" HorizontalAlignment="Center" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
這是控件。
<ewt:DecimalUpDown Tag="{Binding Uid}" Grid.Row="0" Grid.Column="3"
HorizontalAlignment="Stretch" TextAlignment="Left" Margin="10,5,10,5"
FormatString="C2" ShowButtonSpinner="False" VerticalAlignment="Center"
Value="{Binding Value}" LostFocus="DecimalUpDown_LostFocus" />
綁定的動作在此事件處理程序中執行。
好的,你的行動應該做什麼?它是否以某種方式對綁定源採取了行動(例如,綁定窗口發生了什麼?)假設對此問題的答案是肯定的,請參閱下面的答案。 – fourpastmidnight
'DecimalUpDown'是否有問題的文本框?因爲如果是這樣的話,那麼你的'DecimalUpDown'可能會觸發'LostFocus'事件(參見你在'ewt:DecimalUpDown'中發佈的代碼,還有一個'@ LostFocus'屬性)以及文本框 - 它是一個組成部分控制'DecimalUpDown' - 你綁定。 – fourpastmidnight