我正在使用MVVM Cross构建UWP应用程序。 我在绑定命令到按钮时遇到了问题。 以前在XAML页面中,我使用交互性来绑定其他命令。 这里的问题是,我们使用列表视图来呈现用户的“收藏夹”。 UnfavoriteCommand在ViewModel中,但从不被触发,因为User.Favorite列表在模型中,并没有“UnfavoriteCommand”。 如何使用MVVM Cross处理此绑定问题?
<ListView
Grid.Row="0"
Grid.Column="0"
CanReorderItems="True"
CanDrag="True"
AllowDrop="True"
ItemsSource="{Binding User.FavoriteList}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="500" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Grid.Row="0"
HorizontalAlignment="Left"
Margin="0, 0, 0, 0"
Height="25" >
<TextBlock Text="{Binding Description, Mode=TwoWay}"
VerticalAlignment="Center"
TextAlignment="Left"/>
</StackPanel>
<StackPanel VerticalAlignment="Center" Grid.Column="1" Grid.Row="0">
<Button Content=""
FontFamily="{StaticResource FontAwesomeFontFamily}"
BorderBrush="Black">
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="Click">
<Core:EventTriggerBehavior.Actions>
<Core:InvokeCommandAction CommandParameter="{Binding}" Command="{Binding UnfavoriteCommand}"/>
<!--<Core:CallMethodAction TargetObject="{Binding}" MethodName="Unfavorite" />-->
<!--<Core:InvokeCommandAction Command="{Binding UnfavoriteCommand}" InputConverter="{StaticResource buttonConverter}"/>-->
</Core:EventTriggerBehavior.Actions>
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</Button>
</StackPanel>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>