How do I set the selected item of a listbox? When I use SelectedValue, SelectedItem, SelectedIndex, it does nothing. When I use UpdateLayout( ) afterwards, it does nothing. ScrollIntoView( item ) does not appear to do anything.
This is the XAML code for my Listbox. I use a Setter to set the orientation of the listbox to horizontal
<ScrollViewer HorizontalScrollBarVisibility="Visible" Name="DetailedWebViewContainer" VerticalScrollBarVisibility="Disabled" Grid.Row="2">
<ScrollViewer.Resources>
<Style TargetType="ListBox">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"
VerticalAlignment="Center"
HorizontalAlignment="Center"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
</ScrollViewer.Resources>
<ListBox Name="WebScrollView" SelectionMode="Multiple" >
<ListBox.Items>
<phone:WebBrowser Name="LeftBrowser" MinWidth="460" Height="1500" IsHitTestVisible="False" Margin="10, 0, 10, 0"/>
<phone:WebBrowser Name="MiddleBrowser" MinWidth="460" Height="1500" IsHitTestVisible="False" Margin="10,0,10,10"/>
<phone:WebBrowser Name="RightBrowser" MinWidth="460" Height="1500" IsHitTestVisible="False" Margin="10,0,10,0" />
</ListBox.Items>
</ListBox>
</ScrollViewer>
Am I missing something? Greetz GeekPeek
ListBox
in ScrollViewer
? You should put ItemsPanelTemplate
inside of ListBox.ItemsPanel
and remove ScrollViewer
at al - Ku6opr 2012-04-04 07:31
This should work:
<ListBox Name="WebScrollView" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Auto" SelectionMode="Multiple" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.Items>
<phone:WebBrowser Name="LeftBrowser" MinWidth="460" Height="1500" IsHitTestVisible="False" Margin="10, 0, 10, 0"/>
<phone:WebBrowser Name="MiddleBrowser" MinWidth="460" Height="1500" IsHitTestVisible="False" Margin="10,0,10,10"/>
<phone:WebBrowser Name="RightBrowser" MinWidth="460" Height="1500" IsHitTestVisible="False" Margin="10,0,10,0" />
</ListBox.Items>
</ListBox>
SelectedIndex
after tap on some item? Please, provide more info; maybe some xaml or code will be helpfu - Ku6opr 2012-04-04 07:24