简体   繁体   English

如何以编程方式将ListBox.Tooltip绑定到DataTable?

[英]How to Bind ListBox.Tooltip to DataTable programmatically?

How to bind ListBox's * ToolTip * to DataTable? 如何将ListBox的 * ToolTip *绑定到DataTable?

There is only ListBox.ItemsSource , but there is not ListBox.ToolTip.ItemsSource . 只有ListBox.ItemsSource ,但没有ListBox.ToolTip.ItemsSource

ToolTip is a ContentControl , not a ItemsControl . ToolTip是一个ContentControl ,而不是ItemsControl That means that it could contain only single element and not a collection. 这意味着它只能包含单个元素而不包含集合。

To show multiple items in the ToolTip you need to place some ItemsControl ( ListBox , for example) into the TabControl and then use its ItemsSource property. 要在ToolTip显示多个项目,您需要将一些ItemsControl (例如ListBox )放入TabControl ,然后使用其ItemsSource属性。

ListBox list = new ListBox();
ToolTip tooltip = new ToolTip();
ListBox tooltipList = new ListBox();

list.ToolTip = tooltip;
tooltip.Content = tooltipList;
tooltipList.ItemsSource = /*your source*/

You might want to try the following: 您可能想尝试以下操作:

WPF Show data from multiple DataContexts in ToolTip of ItemsControl WPF在ItemsControl的ToolTip中显示来自多个DataContexts的数据

The link above contains a more advanced scenario, however it could be used to extract the code required for your implementation. 上面的链接包含更高级的方案,但是它可以用于提取实现所需的代码。

Hope it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM