c# - 发送 ContentPresented 的内容作为附加的命令参数

标签 c# wpf mvvm command

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/

相关文章:

c# - Datagrid.IsSelected 绑定(bind)和滚动

c# - WPF 的 MVVM 模式 - 不使用任何工具包的二维图

wpf - 切换 View 时保留 ViewModel 的 UI 状态

c# - PostSharp 中的依赖注入(inject)

c# - Bounds.Intersect for WPF

C#/.NET future 相对时间戳?

c# - 单击一次应用程序释放对 MEF 获取的 dll 的锁定

mvvm - 将信息从父 View 模型传递到 subview 模型的正确 MVVM 方法

c# - 如何使用条码渲染框架Codeplex?

c# - 找不到类/添加引用通用窗口