Josh Smith

I have a TextBox whose adorner layer has an adorner which contains a ListBox. The ListBox displays strings (suggested spellings for misspelled words in the TextBox). When the user spells a word incorrectly, they can press F1 to display a list of suggested spellings in the adorning ListBox. After they select a suggestion, the typo in the TextBox is replaced with the selected suggestion. That part works.

I'm having a problem with visual settings. If I'm not mistaken, the adorner (and, hence, the Listbox) is not in the Window's visual tree. That means that the inherited dependency property values of the Window (let's say the FontSize property) will not propogate to the ListBox. With that being the case, how can I achieve such propogation I want the adorning ListBox to look like a ListBox that might be on the actual Window itself (colors, font settings, etc. should all be in sync).

How can I do that Is there a standard way of doing it

Thanks.




Re: Windows Presentation Foundation (WPF) Propogating inherited DPs to the adorner layer

neil mosafi

Hmm good question, not sure what the actual answer is and would be interested to know, but have you considered using the Popup control instead




Re: Windows Presentation Foundation (WPF) Propogating inherited DPs to the adorner layer

Josh Smith

Neil,

I first tried using the Popup to host the ListBox, but there were too many problems. The Popup is a top-level window, so other windows would appear beneath it in the z-order. Also, more importantly, when I moved the Window the Popup would not move along with it. Maximizing/normalizing the window would cause the Popup to "snap" back into place, relative to the TextBox, but moving the Window did not have the same effect. Using an adorner as the ListBox host circumvents both of those issues.

I hope that what I'm trying to do is not a "WPF v2" feature. I really don't want to write a bunch of code which manually sets the ListBox's properties to the "propogated" values.






Re: Windows Presentation Foundation (WPF) Propogating inherited DPs to the adorner layer

Josh Smith

(bump) Even if it's not possible, please just let me know that. Thanks.




Re: Windows Presentation Foundation (WPF) Propogating inherited DPs to the adorner layer

Josh Smith

(bump)




Re: Windows Presentation Foundation (WPF) Propogating inherited DPs to the adorner layer

Josh Smith

(bump)  Somebody, please!  BTW - you can see a demo of the situation in the code download here: http://www.codeproject.com/useritems/SmartTextBox.asp




Re: Windows Presentation Foundation (WPF) Propogating inherited DPs to the adorner layer

Zhou Yong

Hi, Josh, I've also encountered this problem and still ain't have any clue here.

It looks like that this is the general problem with visual layer programming.

Sheva





Re: Windows Presentation Foundation (WPF) Propogating inherited DPs to the adorner layer

Zhou Yong

Hi, Josh, I just chat with Ian Griffiths on msn messenger about this problem, and Ian beats me to the ground, he told me both you and I all miss the AddVisualChild call when doing visual layer programming.
http://msdn2.microsoft.com/en-au/library/system.windows.media.visual.addvisualchild.aspx





Re: Windows Presentation Foundation (WPF) Propogating inherited DPs to the adorner layer

Josh Smith

Thanks Zhou, but I am calling AddVisualChild. In my SmartTextBox I add a ListBox to my UIElementAdorner, and in the ctor I call AddVisualChild passing in the ListBox. I also add the adorner to the SmartTextBox's adorner layer, which means that it cannot be added to the SmartTextBox's visual tree as well. That's the problem. It seems that the visual tree of an element's adorner layer is not "hooked into" the visual tree of that adorned element.




Re: Windows Presentation Foundation (WPF) Propogating inherited DPs to the adorner layer

Zhou Yong

Actually the visuals rendered in the adorner layer is also part of the visual tree, the only difference is that adorners are drawn in a seperate drawing surface.
As to the your question, you shoud remove the AddLogicalChild call in your original code, leave the AddVisualChild call there, and everything works fine. I don't know the reason why the innocuous AddLogicalChild call can make a difference here. some explanation from guys within Microsoft is expected

Sheva





Re: Windows Presentation Foundation (WPF) Propogating inherited DPs to the adorner layer

Zhou Yong

Well, just got the answer from Ian, when overriding logical tree, expect calling AddLogicalChild at right place, you also need to override the LogicalChildren property.

Sheva





Re: Windows Presentation Foundation (WPF) Propogating inherited DPs to the adorner layer

Zhou Yong

I just post an article on how to do visual level and logical level programming, for those interested, you can take a read:
Visual Level Programming vs Logical Level Programming

Sheva





Re: Windows Presentation Foundation (WPF) Propogating inherited DPs to the adorner layer

Josh Smith

Thanks a lot for the help, Sheva.  That makes a lot of sense!

I updated my article and source code download, and mentioned how you helped me find the solution: http://www.codeproject.com/useritems/SmartTextBox.asp

Nice blog post.  That's great information!