views:

215

answers:

1

How would one swap a template by using a Trigger when the items within an ItemsControl overflow its container?

In my current implementation I would like to show a more brief form of template based on whether the current state of the ItemsControl are such that the content would cause a ScrollViwer's scroll bars to appear if the scroll bar visibility was set to Auto. So I'm interested in any property either on the ScrollViewer or the ItemsControl which may give me a clue about whether it is overflowing it's ScrollViewer. If I have to use some custom ValueConverter to make a sensible boolean value to bind to I guess that would be alright too.

A: 

Ok so I ended up figuring this one out myself.

In my case I'm using Logical Scrolling as opposed to physical scrolling and since I'm have a horizontal layout all I had to do was to trigger on the ScrollViewer.ScrollableWidth. The secret to getting this working in my case was to make sure that I set ScrollViewer.HorizontalScrollBarVisibility to Hidden as opposed to Disabled. This will alow the content to be scrolled and will make it so that the scrollableWidth property actually has a meaningful value.

NOTE: Curiously setting HorizontalScrollBarVisibility to Hidden seems to collapse the scroll bar visually so I'm not entirely sure what the difference is between Collapse and Hidden in this case.

jpierson
So I found a problem with this approach. After looking a little closer, modifying the contents of the ItemsControl via a change in the ItemTemplate when the ScrollViewer's ScrollableWidth property changes will cause the ScrollableWidth to change again to accomodate the change in template and therefore start an endless circular binding dependency. If there is a workaround to this then my solution my still be valid otherwise I guess I'm still looking for an alternative solution.
jpierson