I am customizing the tooltip on my user control so that it looks like a callout. The tooltip is set to appear above the control (Placement=Top) with an arrow pointing down toward it.
The problem is when the control is near the edge of the screen, the tooltip is not aligned to the left-side of the control. As a result, the arrow points to an empty space to the left of the control.
Even worse, if the control is near the top of the screen, the tooltip shows up below the target control and the arrow pointing down.
Any idea how to resolve this? I am looking for some way to programmatically create the tooltip on the fly or set a trigger to select the Style based on some properties in the tooltip but I don't know how.
I have faced the same problem in the past and what I did was get the position of the PlacementTarget via PointToScreen(new Point(0,0)) and get the position of the ToolTip by calling the same method and then doing the math to figure out whether the ToolTip is correctly positioned or not. If it wasn't, then I changed the Placement of the ToolTip according to whether it was showing up to the left, right, above or below the PlacementTarget. Also, keep in mind, that PointToScreen() will only work once the ToolTip has rendered so attach a handler to ToolTip.Open and do it in there. Hope this helped. Let me know if you come across a more efficient/better way to solve this problem.
Related
I'm making a custom dropdown button (since the one included in wpf requires too much hacking to style right). Now that i got the button bit out of the way i need to add the drop down part.
My first thought was to add a stackpanel and use that to contain the items but it gets cut off if it leaves the borders of the grid that the button is in. Next up was the popup primitive, it gets on top of everything nicely enough but position wise it just free floats and i haven't figured out how to make it follow the button it was spawned by. I also tried using contextmenu but that seems to have no positioning controls at all and just sits where the mouse made it..
Anyways wpf is a big package and I'm just getting into it, anybody know which direction i might find what I'm looking for?
Preferred approach normally is to use a Popup. You got two very important properties with a Popup
PlacementTarget and Placement
Setup a binding for PlacementTarget on the Popup to your custom Button and then use Placement to position the Popup accordingly w.r.t to the PlacementTarget(Button)
Placement accepts an enum of type PlacementMode which gives you quite a few options to position the Popup.
I am designing a code viewer using a virtualized ListView control to display code lines.
Now I want to create a highlight effect when the user clicks a link which takes them to a particular line. I want the target line to be highlighted.
The effect will be either an "underline" appearing (and disappearing) or a semi-transparent overlay (like a marker pen) appearing (and disappearing). The actual graphical effect itself is unimportant, that's not the problem.
What is the best approach to achieve this? I'm not quite sure where to start.
Some technical requirements might be that I need to:
find the right events to react to - or use databinding
obtain the absolute bounding rectangle of the virtualized target item (although when brought into view the item should be available)
absolutely position a canvas effect on top, fade in and fade out
...Ideally some state changes in a view model, a piece of XAML is animated via a triggered storyboard to appear (fade in) above the relevant ListViewItem and then animates away again (fade out). Of course before the fade in, the element must already be correctly positioned over the relevant ListViewItem...
I have worked on a search feature for a Listview where every ListViewItem had few textbocks. When the user types something in a search textbox, all the matches in the listview was supposed to get highlighted.
I created Run objects based on the search string (used Regex to find the match) and then set the Background to some color. Also, held the reference of the ListViewItem in the tag of the Run object which helped me to use call ScrollIntoView. Hope this will be of some help in your case.
I want to show all the ToolTips on a view as soon as it's opened. That's fine, I can set the ToolTip.IsOpen properties to true. That certainly shows the ToolTips, the problem is they all show up at (0, 0). Apparently the positioning of the ToolTips doesn't happen until its target control is hovered. Only after hovering are the ToolTips positioned correctly. Setting focus to all the controls first doesn't help either; the target control has to receive the hover event. I'm assuming the ToolTip hooks into the hover event of its target and positions itself inside this event. Is there a protected method I can call in a ToolTip subclass or some such?
ToolTipService.SetPlacement(button1,
System.Windows.Controls.Primitives.PlacementMode.Top);
See this MSDN Page to see all the placement options
EDIT
See this article about the custom positioning of tooltips. It refers to a project on codeplex that contains the code: SmartToolTips
As far as I can tell what I'm asking here is not possible beyond manually doing layout or customizing the source. I implemented a completely custom tooltip instead. sigh
I'm building a silverlight app in Blend that will contain a treeview and treeviewitems. The contents of my treeviewitems all have a blue border (when clicked and when you hover the mouse over), as you can see in the image I linked to. I cannot figure out what causes that border, or how to remove it; anyone know where to get at it? I've tried looking in the various treeview related templates, but I've had no luck so far.
I think what you are seeing here is the FocusVisual:
http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.focusvisualstyle.aspx
If you set this to {x:Null} (via FocusVisualStyle), it should go away...if not, you're likely dealing with a "selected" VisualState, in which case your best option is to override the template to remove that particular state.
From what I understand, the popup exists within it's own visual tree. However, I've noticed a few properties, Clip and ClipToBounds. What I am wanting to do is Visually clip a popup at the right and bottom edges of a window regardless of the fact that the popup is independent of the bounds of the window. I'm not using XAML, but if somebody knows how to do it in XAML, then that's fine. I can get to the main window using System.Windows.Application.Current.MainWindow. Is it possible from this to get a value that I can use to clip the popup? I'm assuming that if there is a value that I can use, then I would be able to bind the clipping of the popup to that value. This is really not necessary since after the popup initially opens, if the window gets moved or resized, the popup closes. So I would really only need to clip the popup when it opens. The reason I would like to do this is because although I am using a popup, I don't want it to appear as a popup that exists outside of the window. FYI this is for a popup calendar for a custom datebox. Any ideas, as well as clarification of misconceptions that I may have, would be greatly appreciated.
Furthermore, the popup can be launched from a user control that is not directly on the Main Window. So in that case it would be easier to use a popup. As apposed to a UC inside the XAML
I know this is a year old post, but in case any others come here looking for answers... If you don't need the popup to be outside of your window, why use a popup at all? It'd be far easier to simply use a control in a canvas (for instance) and control it via its Visibility property. Then you'd automagically get your clipping.