I have a listbox (with normal vertical orientation), each element of which is a listbox with horizontal orientation. I want to have a ScrollBar inside of internal listbox.
My code is:
<Window.Resources><HierarchicalDataTemplate x:Key="ItemTemplateSchedule"><ListBox><ListBox.ItemsPanel><ItemsPanelTemplate><StackPanel Orientation="Horizontal" /></ItemsPanelTemplate></ListBox.ItemsPanel><ListBoxItem>My-Very-Long-Item-Nimber-1___</ListBoxItem><ListBoxItem>My-Very-Long-Item-Nimber-2___</ListBoxItem><ListBoxItem>My-Very-Long-Item-Nimber-3___</ListBoxItem><ListBoxItem>My-Very-Long-Item-Nimber-4___</ListBoxItem><ListBoxItem>My-Very-Long-Item-Nimber-5___</ListBoxItem></ListBox></HierarchicalDataTemplate></Window.Resources><Grid><ListBox ItemTemplate="{StaticResource ItemTemplateSchedule}" >></ListBox></Grid>
So, I have a solution for this question - I need set the width property for internal listbox according of current width of outer listbox :
Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ListBox}, Path=ActualWidth}"
Now I want add some new control in each row of outer listbox:
<HierarchicalDataTemplate x:Key="ItemTemplateSchedule"><StackPanel Orientation="Horizontal" Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ListBox}, Path=ActualWidth}"><TextBlock Text="This is Text in a TextBlock"/><ListBox ><ListBox.ItemsPanel><ItemsPanelTemplate><StackPanel Orientation="Horizontal" /></ItemsPanelTemplate></ListBox.ItemsPanel><ListBoxItem>My-Very-Long-Item-Number-1___</ListBoxItem><ListBoxItem>My-Very-Long-Item-Number-2___</ListBoxItem><ListBoxItem>My-Very-Long-Item-Number-3___</ListBoxItem><ListBoxItem>My-Very-Long-Item-Number-4___</ListBoxItem><ListBoxItem>My-Very-Long-Item-Number-5___</ListBoxItem></ListBox></StackPanel></HierarchicalDataTemplate>
And now it doesn't work! Now I have a Scrollbar in outer listbox again...
So, can I solve this problem? Any ideas?