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>

 

posted @ 2019-01-08 16:06  I'm CY  阅读(246)  评论(0编辑  收藏  举报