由于我将 View 移到 ItemsControl 中,因此无法在 ViewModel 中触发 EventTrigger。这是我的命令声明,应该在 LostFocus 上触发:
public ICommand UpdateOrdersCommand { get; set; }
public void UpdateOrders(object param)
{
UpdateFields();
}
我的容器 XAML:
<UserControl.Resources>
<WMS:PurchasingModel x:Key="ViewModel" />
<DataTemplate x:Key="myDataTemplate1">
<WMSViews:Purchasing1 />
</DataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot"
Background="White"
DataContext="{StaticResource ViewModel}">
<ItemsControl ItemsSource="{Binding Path=ColPurchasing}"
ItemTemplate="{StaticResource myDataTemplate1}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
我的观点,这个 EventTrigger 曾经在 LostFocus 上触发:
<Classes:TextBoxEx TabIndex="1"
x:Name="tbFoodSales"
HorizontalAlignment="Left"
Height="23"
Margin="55,79,0,0"
TextWrapping="Wrap"
VerticalAlignment="Top"
Width="61"
TextAlignment="Right"
Text="{Binding Path=FoodSales, Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="LostFocus">
<i:InvokeCommandAction Command="{Binding UpdateOrdersCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Classes:TextBoxEx>