wpf - 如何将 Popup(或 ContextMenu)的 PlacementTarget 绑定(bind)到 UserControl 中的元素?

标签 wpf xaml binding popup contextmenu

在这样的场景中:

<Grid>
...
   <local:MyControl x:Name="MyCtl" Grid.Row="1"/>
   <Popup PlacementTarget="{Binding ???}"/>
<Grid>

我需要将 PlacementTarget 绑定(bind)到名为 MyBtn 的按钮在 内我的Ctl。什么是最干净的方法?

最佳答案

<Popup PlacementTarget="{Binding ElementName=MyCtl}" />

关于wpf - 如何将 Popup(或 ContextMenu)的 PlacementTarget 绑定(bind)到 UserControl 中的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2098579/

相关文章:

c# WPF AlternateContent 在命名空间中不存在 [...]

c# - 现有 Canvas 中的 ItemsControl

c# - WPF 从 ViewModel 打开一个新 View

c# - 绑定(bind)自定义属性类 WPF

wpf - MVVM Light DataGrid 绑定(bind)

c# - 如何在运行时更改 wpf 中的 xmldataprovider 源?

wpf - 如何绑定(bind) WPF 中另一个程序集中的类的属性?

c# - 如何在样式内的 WPF DataTemplate 中使用绑定(bind)

wpf - 如何取消动画 WPF DependencyProperty?

javascript - 在 Silverlight 中如何附加到 ScriptObject 上的事件?