我在视图中包含的用户控件中绑定命令时遇到问题。
用户控件.xaml
<DataTemplate x:Key="SoldItemDataTemplate" x:DataType="data:SoldItem">
<Grid HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
...
</Grid.ColumnDefinitions>
...
<TextBox Grid.Column="2" Text="{x:Bind q}">
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="TextChanged">
<Core:InvokeCommandAction Command="{Binding Path=DataContext.QChanged, ElementName=SoldRows}" CommandParameter="{Binding Mode=TwoWay}"/>
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</TextBox>
</Grid>
</DataTemplate>
...
<ListView x:Name="SoldRows"
ItemsSource="{Binding SoldItemsList , Mode=TwoWay}"
IsItemClickEnabled="True"
ItemTemplate="{StaticResource SoldItemDataTemplate}">
...
主页.xaml
<Page.DataContext>
<vm:MainPageViewModel x:Name="ViewModel"></vm:MainPageViewModel>
</Page.DataContext>
...
<controls:UserControl Grid.Row="1"></controls:UserControl>
...
MainPageViewModel.cs
...
private DelegateCommand<object> _QSoldChanged;
...
public DelegateCommand<object> QSoldChanged
{
get
{
if (_QSoldChanged == null)
{
_QSoldChanged = new DelegateCommand<object>((object par) =>
{
...
});
}
return _QSoldChanged;
}
}
所以,我想在 TextChanged 事件上调用 QSoldChanged,但没有任何反应。我错过了什么?在这种情况下,这是设置命令的正确方法吗?如果您需要更多,请询问!提前致谢