I have two separate ItemsControls that appear side by side. The ItemsControls bind to the same ItemsSource, but they display the data differently.
Each item displayed on the left will most likely be smaller than the same item on the right. This causes a problem because the rows will not line up, so I need the item on the left to bind to the item on the right.
ItemsControl ItemsControl
|Item 1 |Item 1
|Item 2 |Item 2
|Item 3 |
|Item 4 |Item 3
As you can see, Item 2 on the right is larger, so it throws off the alignment. So if I can bind left's Item 2 to right's Item 2's ActualHeight the problem would be solved. How can I do this in XAML?
Edit: To make things more complicated, the ItemsControl on the right needs to scroll right to left, but both ItemsControls need to scroll up and down together. Basically, the left one provides a header of sorts for the items on the right.
Following up on Jobi Joy's answer
You can't do a direct
OneWayToSourceBinding in Xaml for the ReadOnly Dependency Property ActualHeight but there are many workarounds. The answer by Kent Boogaart in this question is my favorite. What is does is that it uses an Attached Behavior that listens to theSizeChangedevent of anyFrameworkElementand updates two Attached Properties, Width and Height, accordingly.With a
TextBlockfor example,ActualHeightcan be used to push into a Height property of the ViewModel likeSynkronize two ScrollViewers
You can either use a
DependencyPropertyDescriptorto listen for changes in theVerticalOffsetPropertyproperty or subscribe to theScrollChangedevent and callScrollToVerticalOffset. ExampleXaml
Code behind event handlers
ActualSizeBehavior