本文介绍了工具提示和菜单项显示在屏幕的左上角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我的wpf应用程序中有几个按钮,以及带菜单项的一些菜单。问题是,每当我将鼠标悬停在我的按钮上时,工具提示都会显示在屏幕的左上角,当我点击菜单时,菜单项也会显示在屏幕的左上角。 我目前正在使用Visual Studio 2010,而我正在运行Windows 7 64位。 怎么样?我解决了这个问题? 如果这会有所帮助,这里有一个按钮上使用的控件模板示例: < ControlTemplate x:键 = CompileButton TargetType = {x:类型按钮} > < 网格 工具提示 = 运行所有测试cas es 光标 = 手 > < Ellipse x:名称 = ell 描边 = 黑色 StrokeThickness = 0 > < Ellipse .Fill > < ImageBrush ImageSource = Images / Compile.png / > < / Ellipse.Fill > < / Ellipse > < / Grid > < ControlTemplate.Triggers > < 触发器 属性 = 按钮。 IsMouseOver 值 = True > < Setter TargetName = ell 属性 = 不透明度 值 = 0.7 / > < / Trigger > < / ControlTemplate.Triggers > < / ControlTemplate > 解决方案 想想你需要做的是使用 ToolTipService.PlacementRectangle http://msdn.microsoft.com/en-us/library/system.windows.controls.tooltipservice.placementrectangle.aspx [ ^ ] I have a few buttons in my wpf application, as well as a few Menu's with menu items. The problem is that whenever I hover over my buttons, the tooltip is being displayed at the upper left corner of my screen, and when I click on a menu, the menu items are also displayed on the upper left corner of the screen.I am currently using Visual Studio 2010, and I am running Windows 7 64bit.How can I resolve this?If this would help, here is a sample of a control template used on a button:<ControlTemplate x:Key="CompileButton" TargetType="{x:Type Button}"> <Grid ToolTip="Run all test cases" Cursor="Hand"> <Ellipse x:Name="ell" Stroke="Black" StrokeThickness="0"> <Ellipse.Fill> <ImageBrush ImageSource="Images/Compile.png"/> </Ellipse.Fill> </Ellipse> </Grid> <ControlTemplate.Triggers> <Trigger Property="Button.IsMouseOver" Value="True"> <Setter TargetName="ell" Property="Opacity" Value="0.7" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> 解决方案 Think what you need to do is use the ToolTipService.PlacementRectangle http://msdn.microsoft.com/en-us/library/system.windows.controls.tooltipservice.placementrectangle.aspx[^] 这篇关于工具提示和菜单项显示在屏幕的左上角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-31 03:20