Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Xamarin.Forms ChangeCanExecute未使用正确的参数_C#_Xamarin_Xamarin.forms_Uwp_Freshmvvm - Fatal编程技术网

C# Xamarin.Forms ChangeCanExecute未使用正确的参数

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

我有一个在UWP中运行的Xamarin.Forms应用程序,其中我使用DLToolkit.Forms.Controls.FlowListView(from)来显示某种带有按钮的网格视图

使用的Mvvm框架是FreshMvvm

以下是我在XAML中的gridview:

<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