Wednesday, 14 August 2013

How to change control alignment depending on available space?

How to change control alignment depending on available space?

Imagine this. I've got a Border which contains some custom wpf control,
lets call it MyControl. This Border stretches itself when window is
resized (to fill available space). MyControl size is fixed. Now, I want my
control to have HorizontalAlignment="Center" when it fits the available
space, and HorizontalAlignment="Left" when it doesn't. I'm having trouble
figuring out how to implement such behaviour though.
I guess, i can subscribe to Border's SizeChanged event and change
alignment in code-behind depending on ActualWidths of Border and
MyControl, but isn't there an easier way? Can this be achieved by
databinding or by attached behaviour?

No comments:

Post a Comment