我有一個問題來綁定包含在視圖中的用戶控件中的命令。UWP InvokeCommandAction在ListView MVVM內的TextBox
UserControl.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}">
...
MainPage.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;
}
}
所以,我想打電話QSoldChanged,在TextChanged事件,但沒有發生。我錯過了什麼?這是在這種情況下設置命令的正確方法嗎? 如果您需要更多隻是問! 在此先感謝
問題是X:文本框的綁定。它的模式是一種方式。所以文本更改不反映視圖模型。將其更改爲綁定。希望它有效 – Archana