Silverlight DescriptionViewer 防止工具提示在单击时消失
Silverlight 4 DescriptionViewer
控件在工具提示中显示 Description
:
语法非常简单:添加命名空间 xmlns:dataInput="clr-namespace:System.Windows。 Controls; assembly=System.Windows.Controls.Data.Input"
和以下 XAML 到您的 UserControl:
<dataInput:DescriptionViewer Description="Some hints on user input etc." />
不幸的是,某些用户单击显示的图标(因为它甚至默认情况下悬停),这会立即关闭工具提示(实际且唯一的信息)。更糟糕的是,当您悬停后快速单击时,工具提示甚至根本不会出现,因此用户可能会认为图标根本没有任何功能。
我想防止在单击时关闭工具提示(只需在“鼠标移开”时关闭),更好的单击应该强制工具提示立即显示(在显示之前跳过通常的超时)。
不过,这似乎比我更难,因为没有 OnClick
事件,而且 MouseLeftButtonDown
似乎根本没有触发。我还尝试覆盖 DescriptionViewer
控件,但也没有找到合适的方法来覆盖。
你能帮忙吗?谢谢你!
The Silverlight 4 DescriptionViewer
Control displays a Description
in a Tooltip:
The syntax is pretty easy: Add Namespace xmlns:dataInput="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input"
and the following XAML to your UserControl:
<dataInput:DescriptionViewer Description="Some hints on user input etc." />
Unfortunately, some users click on the displayed Icon (since it even hovers by default) which instantly closes the Tooltip (the actual and only information). Even worse, when you click very quickly after hovering, the Tooltip even won't appear at all, so the user might think the Icon has no function at all.
I'd like to prevent closing the Tooltip on Click (just close on "mouse out"), even better clicking should force the Tooltip to show immediately (skipping the usual timeout before shown).
It seems to be harder then I though, since there is no OnClick
event and also MouseLeftButtonDown
seems to not fire at all. I also tried to override the DescriptionViewer
Control but also no luck finding the appropriate methods to override.
Can you help? Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这实际上与DescriptionViewer无关,它是ToolTip的行为。单击鼠标后,工具提示就会消失。在这种情况下,您可能想编写自己的工具提示。
我认为通常当您单击 DescriptionViewer 图标时,应该会打开一个新窗口,就像一个更详细的帮助页面。这样用户就不会感到困惑。
更新:
您可以通过定义附加属性来实现此目的。基本上,您可以将此属性附加到 DescriptionViewer 内的 Button。当按钮的 Click 事件被触发时,您会在按钮下方找到工具提示并将其 IsOpen 设置为 ture。然后,您还需要处理 MouseLeave 事件,以便在鼠标离开后隐藏工具提示。
这就是附加属性的定义方式。
公共静态类 ButtonAttachedProperties
{
公共静态 bool GetOpenToolTip(DependencyObject obj)
{
返回 (bool)obj.GetValue(OpenToolTipProperty);
然后
,
在 DescriptionViewer 的样式中,将该属性附加到 Button。此外,您还需要命名工具提示,以便能够使用附加属性类中的 FindName 找到它。
希望这有帮助。 :)
this actually has nothing to do with the DescriptionViewer, it is the behavior of the ToolTip. The ToolTip will disappear once you do a mouse click. In this case you might want to write you own ToolTip.
I think normally when you click on the DescriptionViewer icon, there should be a new window open which is like a more detailed help page. So the user wouldn't get confused.
Update:
You can achieve this by defining an attached property. Basically, you attach this property to the Button inside your DescriptionViewer. When the Button's Click event is fired, you find the Tooltip underneath the Button and set its IsOpen to ture. Then you also need to handle the MouseLeave event to hide the Tooltip once your mouse's away.
This is how the attached property is defined.
public static class ButtonAttachedProperties
{
public static bool GetOpenToolTip(DependencyObject obj)
{
return (bool)obj.GetValue(OpenToolTipProperty);
}
}
Then in the DescriptionViewer's style, you attach the property to the Button. Also you need to name the Tooltip in order to be able to find it using FindName in the attach property class.
Hope this helps. :)