WPF - adorner stays in original position after view transitions - wpf

I have a control template defined, call it myVal, that is used for validation - this is then used for example in a Style targeting textbox where its Validation.ErrorTemplate is set as
Now say there are a number of such textboxes that sit in a view and that this slides in using TranslateTransform and BeginAnimation.
The result is that the adorner used in the ErrorTemplate doesn't follow the position of the textboxes as the view transitions - instead these stay in the starting position. However, the adorners reposition themselves correctly in relation to the textboxes as soon as I set focus or events such as mouse move.
How can I get the adorners to show in the correct position after the transformation without having to change the focus? Is there a way of delaying the validation until after the transition...or how can I "revalidate" the properties once the animation has finished? I read somewhere about calling invalidatevisual but can't see how I'd do that. Any help is much appreciated.
Cheers

Two ideas:
Try adding an AdornerDecorator around the textbox, or around the group of textboxes. This will tell WPF to add another layer for rending adorners. Adding a layer "closer" to the textboxes might help.
If you want to tell the adorner layer to re-render itself, then you can use something like the following code:
var al = AdornerLayer.GetAdornerLayer(myTextBox);
al.Update();

Related

WPF - datagrid adorner not updating upon binded PropertyChanged

I am using a solution found here: http://malor.se/blog/?p=88 to add adorners to a datagrid text column. Works fine, except my adorner is binded to the underlying object, and it's failing to update upon source property changes. I can even bind the cell contents and the adorner text to the same property, and the cell content will reflect property changes while the adorner text doesn't. The adorner seems to refresh only when I do something to force a redraw of the cell, like resizing the column.
Is there a fairly non-hackish way I can get the adorner to refresh upon source property changes like other normal wpf controls?
Web searching seems to indicate that the adorner layer refreshes only on certain events, like a resizing, for the sake of performance I suppose. I'm now of the opinion that maybe it's not the best choice for my particular task.

programmatically making a dropdown menu in vb.net WPF

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.

How to get an existing property from style

I'm developing a WPF project where I need to validate textboxes on code-behind and then change the border color of those textboxes to some unknown color defined by the user configuration; the problem is that to overwrite the MouseOver effect I would need to set the value from XAML directly via ControlTemplate or Style.
Is there a way to get the current value assigned to the TextBox from XAML? Maybe binding it to itself?
I will appreciate any help you can give.
When validating a TextBox, or any control for that matter, it's common to use an adorner to display the validation error (in your case, setting the border color). You can have a look at an example here.
Using this method, you don't actually change the TextBox's border, but create a new visual layer on top of the TextBox that draws the new border around it. This is pretty much the way validations should be done in WPF, and it also solves your problem of having to deal with changing the TextBox's border value back and forth.

WPF Adorner Overlay Problem

I am trying to achieve functionality similar to that of a Popup, without using a Popup, but instead adorning my ContentControl with a basic adorner. Basically, I want the ContentControl to have an "overlay" effect, whereby it is the topmost object, above all other elements - similiar to that of the Popup control.
Here is the problem that I am running into, and I am hoping that someone can point out where I am going wrong:
I have a stand grid with two row definitions. The first row contains a UI element - for example, a rectangle. The second row contains a custom control that I have developed to emulate the functionality of a "drawer" sliding out. Basically, when I click on button, I am going to animate a TranslateTransform to "slide" my ContentControl "up". This works fine - except that it gets cropped underneath the rectange in the first row of the grid. If I remove the row definitions in the grid, then when the desired behavior is achieved - the ContentControl is moved "up" and partially "on top" of the rectangle. The rectangle is merely a place holder for what I am trying to achieve. I basically want to have a drawer type control that can slide out and be on top of all other controls.
I am somewhat new to using the Adorner class, so, I am hoping that someone can please point out where I am going wrong.
Thanks.
Chris
Change the parent of the adorner to the full grid, and not just your control. If you put a control in a grid row, and set the adorner to adorn the control, it will usually be clipped to that row because the control is.

Tooltip adorner

I am using a third party charting library (Infragistics xamChart). I am not satisfied with how tooltips are displayed on a line charts datapoints so I was thinking of using an adorner to make a better looking/interactive tooltip.
What I want to do is have the adorner popup whenever one of the datapoints is hovered over. Does anyone have any pointers on how I can do this? Most of the adorner samples I found are pretty simple ones that just alter the entire control they are adorning.
My main questions are:
Is it possible for an adorner to
appear only when certain elements are
hovered over (and have it appear at
the current cursor position)?
Does anyone have a simple sample they
can share?
Are adorners the right way to go
here? I think the only other option
was to use the popup control but I
though adorners were a nicer
solution.
Thank you.
Perhaps Attached Behaviours could help you? From this article:
The idea is that you set an attached
property on an element so that you can
gain access to the element from the
class that exposes the attached
property. Once that class has access
to the element, it can hook events on
it.
That way you could attach a listener to the MouseEnter event and display your custom ToolTip from there.

Resources