In my application there is one Listbox and one textblock both are coupled inside a scrollviewer. Means I want to scroll both listbox and textblock together (following XAML may explain better ). I want to show some text in textblock from listbox which item is currently visible on screen. So I have to know which item is currently visible on screen.
Right now I have no clue what to do. Any suggestion or comment is appreciable. Thanks in advance.
<ScrollViewer HorizontalScrollBarVisibility="Auto">
<StackPanel>
<ListBox x:Name="myListBox" SelectionChanged="SelectinoChanged" Height="150">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation ="Horizontal" >
<StackPanel.RenderTransform>
<TranslateTransform X="0"/>
</StackPanel.RenderTransform>
开发者_如何学Go </StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding name}" FontSize="30"/>
<Button Content="{Binding name}" FontSize="30" Name="but" Click="but_Click"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock Name="tb" TextWrapping="Wrap" FontSize="40" Height="50" />
</StackPanel>
</ScrollViewer>
the Listbox contains a ScrollViewer in it.
so you should just remove your ScrollViewer !
<StackPanel>
<ListBox x:Name="myListBox>
...
</ListBox>
<TextBlock Name="tb"/>
</StackPanel>
and maybe set on the ListBox
HorizontalScrollBarVisibility="Auto"
精彩评论