在MVVM demo app by Josh Smith , 当您尝试通过那个 选项卡(不是 当前选定的选项卡)上的关闭按钮关闭一个选项卡时,它不会关闭,而是关闭选定的标签。
我如何修改代码,以便当我点击不是当前选中的选项卡项的关闭按钮时,它会关闭右侧的选项卡?
请注意,我已尝试使用 AttachedProperties
和以下内容:
AttachedCommand:CommandBehavior.Event="Click"
AttachedCommand:CommandBehavior.Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.CloseWorkspaceCommand}"
AttachedCommand:CommandBehavior.CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext}"
我传入 CommandParameter
的地方,但这会获取托管 View 的 ViewModel,而不是绑定(bind)到 ContentPresenter
的 View 模型。
感谢您的宝贵时间。
最佳答案
尝试只使用它,它将直接绑定(bind)到 View 的数据上下文
AttachedCommand:CommandBehavior.CommandParameter="{Binding}"
希望对您有所帮助。
关于c# - 发送 ContentPresented 的内容作为附加的命令参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20927304/