C# Xamarin.Forms ChangeCanExecute未使用正确的参数
我有一个在UWP中运行的Xamarin.Forms应用程序,其中我使用DLToolkit.Forms.Controls.FlowListView(from)来显示某种带有按钮的网格视图 使用的Mvvm框架是FreshMvvm 以下是我在XAML中的gridview:C# Xamarin.Forms ChangeCanExecute未使用正确的参数,c#,xamarin,xamarin.forms,uwp,freshmvvm,C#,Xamarin,Xamarin.forms,Uwp,Freshmvvm,我有一个在UWP中运行的Xamarin.Forms应用程序,其中我使用DLToolkit.Forms.Controls.FlowListView(from)来显示某种带有按钮的网格视图 使用的Mvvm框架是FreshMvvm 以下是我在XAML中的gridview: <c:FlowListView SeparatorVisibility="None" HasUnevenRows="False" FlowColumnMinWidth="100" FlowItemsSour
<c:FlowListView SeparatorVisibility="None"
HasUnevenRows="False" FlowColumnMinWidth="100"
FlowItemsSource="{Binding Boards}">
<c:FlowListView.FlowColumnTemplate>
<DataTemplate>
<Button Text="{Binding Number}"
Command="{Binding Path=BindingContext.SelectBoardCommand, Source={x:Reference Name=SalesPage}}"
CommandParameter="{Binding .}" />
</DataTemplate>
</c:FlowListView.FlowColumnTemplate>
</c:FlowListView>
与列表中的最新项一起
此外,我需要在ChangeCanExecute中添加一个“board!=null”,因为这个Func在很多时候都是用null值调用的
有什么想法吗?我认为有两种方法可以解决你的问题:
1) 在
BoardModel
内移动SelectBoardCommand
。它不需要一个参数,将在每个模型上单独运行2) 将
按钮的属性
绑定到未使用
属性。在这种情况下,,用户将无法从UI调用SelectBoardCommand
。您确定这不是FlowListView的问题吗?@Andy刚刚测试过,同样的问题我无法将命令放入BoardModel中,因为命令中有更多与我的ViewModel紧密耦合的代码。我已经尝试绑定到Enabled属性但是一旦你用命令绑定你的按钮,Enabled就不再使用了。如果我们记住,从技术上讲,我们使用ListView
和ItemTappedCommand
,该命令不应该有CanExecute
返回false
。单元格始终可以点击,但在我们放入的if(board?.NotUsed){…}
实现中,这是一个很好的解决方法,即使在视觉上,按钮始终处于启用状态。我接受您的回答,感谢您的评论“if(board?.NotUser)”。。。谢谢
private ICommand _selectBoardCommand;
[DoNotNotify]
public ICommand SelectBoardCommand => _selectBoardCommand = new Command<BoardModel>(board =>
{
board.NotUsed = false;
((Command<BoardModel>) _selectBoardCommand).ChangeCanExecute();
}, board => board != null && board.NotUsed);
((Command<BoardModel>) _selectBoardCommand).ChangeCanExecute();
board => board != null && board.NotUsed