stu*_*bax 1 wpf xaml mouseover tooltip itemscontrol
这里的问题.我有一个ItemsControl,如果用户将鼠标悬停在ItemsControl上,我想显示一个工具提示.看起来很简单吧?
这是一个例子:
<ItemsControl BorderBrush="Blue" BorderThickness="1">
<ItemsControl.ToolTip>
<ToolTip Content="Text" />
</ItemsControl.ToolTip>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<Label BorderBrush="Red" BorderThickness="1">One</Label>
<Label BorderBrush="Red" BorderThickness="1">Two</Label>
<Label BorderBrush="Red" BorderThickness="1">Three</Label>
<Label BorderBrush="Red" BorderThickness="1">Four</Label>
<Label BorderBrush="Red" BorderThickness="1">Five</Label>
<Label BorderBrush="Red" BorderThickness="1">Six</Label>
<Label BorderBrush="Red" BorderThickness="1">Seven</Label>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)
使窗口宽度足够小,让WrapPanel包装一个项目.并尝试将鼠标悬停在ItemsControl上(ToolTip不会出现),而不是将鼠标悬停在Label上(将出现ToolTip).
为什么这种行为是正确的,以及如何在这种情况下强制使用ToolTip?
ToolTip因为ItemsControl在任何情况下都没有显示,直到你给Backgrounda Brush.
<ItemsControl Background="Transparent"
Run Code Online (Sandbox Code Playgroud)