MVVM ICommand.CanExecute parameter is null

CommandParameter="{Binding}"

改为

CommandParameter="{Binding DataContext,RelativeSource={RelativeSource Self}}"
                            <StackPanel Orientation="Horizontal" >
                                <Button Content="×" CommandParameter="{Binding DataContext,RelativeSource={RelativeSource Self}}" Command="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=DataContext.CmdConvertToFalse}"></Button>
                                <Button Content="√" CommandParameter="{Binding DataContext,RelativeSource={RelativeSource Self}}" Command="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=DataContext.CmdConvertToTrue}"></Button>
                            </StackPanel>

猜你喜欢

转载自www.cnblogs.com/rock_chen/p/10239513.html