[英]LostFocus event firing upon getting Focus
我有一個綁定到對象集合的項目itemscontrol
。
在數據模板中,我綁定了一個動作,如果失去了焦點,該動作將由所有創建的控件使用。
在控件中,有一個文本框,因此,如果項目控件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" />
綁定操作在此事件處理程序中執行。
如果您的操作應該更新綁定的源(例如,Window,如您的示例所示),則您可能想要嘗試將OneWayToSource
添加到您的Binding中,以便綁定僅以一種方式發生-從文本框到其綁定的任何位置至。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.