【发布时间】:2017-07-10 16:35:49
【问题描述】:
我正在使用 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>
【问题讨论】:
标签: c# xaml listview uwp mvvmcross