如何设置列表框的选定项? 当我使用SelectedValue,SelectedItem,SelectedIndex时,它什么都不做。当我之后使用UpdateLayout()时,它什么都不做。 ScrollIntoView(item)似乎没有做任何事情。
这是我的Listbox的XAML代码。我使用Setter将列表框的方向设置为水平
<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>
我错过了什么吗? Greetz GeekPeek
答案 0 :(得分:2)
这应该有效:
<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>