然后发现"{Binding $parent[ItemsControl].DataContext.ParentCommand}" 这种写法不能用了,会报错 Unable to resolve property or method of name 'ParentCommand' on type 'System.Object'。GPT-4 和 Claude 都完全不懂这个变化,一直指导我排查别的东西,折腾了好久也没解决。
只好去 Discord 上问群友,群友说是 11 新加的 CompileBindings 导致的,默认开启,必须把 CompileBindings 关掉,或者每次调用 Parent Command 都写 Command="{Binding $parent[ItemsControl].((vm:ParentViewModel)DataContext).ParentCommand}" 这么长一大坨。(不写 .NET 的 v 友可以理解为每次从 for 循环里 call 一个循环外面的函数要写 89 个字符)从 list 调用母 vm 的 Command 可是一个非常常见的操作,本来写 $parent[ItemsControl].DataContext.ParentCommand 就已经很长很难看,现在还要再加一段。为什么就不解决一下呢?