我对ScrollIntoView
...
上次我使用这种方法并且一切正常。但现在我遇到了问题,我不知道为什么。
我认为我看了90%的互联网关于这个主题,我没有发现它......
这是我的XAML:
<Grid Grid.Row="1" >
<ListView
x:Name="NameOfList"
HorizontalAlignment="Stretch"
IsZoomedInView="False"
ItemsSource="{Binding someSource}"
ItemTemplate="{StaticResource someTemplate}"
IsItemClickEnabled="True"
someNamespace:ItemClickedToCommand.Command="{Binding someCommand}"
SelectedItem="{Binding someSelecteditem, Mode=TwoWay}"
SelectedIndex="{Binding someselectedindex, Mode=TwoWay}"
ItemContainerStyle="{StaticResource someContainerStyle}"
>
</ListView>
</Grid>
这是我的代码隐藏:
var page = GetPage();
var someGrid = page.FindName("SomeGridUserControlGrid") as Grid;
var someUserControl = someGrid.FindName("someUserControl") as SomeUserControl;
ListView listViewSome = someUserControl.FindName("SomeListView") as ListView;
// listViewSome is not null, this object has correct value
//but code below doesn’t work…
listViewSome.SelectedItem = someSelecteditem;
listViewSome.ScrollIntoView(listViewSome.SelectedItem);