Silverlight ListBox控件在單擊顯示列表項時自動移動滾動框(如果列表框顯示5個項目,請單擊最後一個項目,並將所有項目向下移動一個)。我的QA團隊發現了一個錯誤,告訴我這對我們的具體情況會造成混淆。我如何覆蓋這種行爲?如何覆蓋Silverlight ListBox的默認行爲?
<ListBox x:Name="accountsListBox" Margin="8,65,8,8" SelectionChanged="accountsListBox_SelectionChanged" VirtualizingStackPanel.VirtualizationMode="Recycling">
<ListBox.BorderBrush>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="Silver" Offset="1"/>
</LinearGradientBrush>
</ListBox.BorderBrush>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Height="19" Text="{Binding}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
List<string> names = new List<string>();
for (int i = 0; i < 100; i++)
{
names.Add("Name " + i);
}
this.accountsListBox.ItemsSource = names;
}
private void accountsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// this was an attempt but causes other unwanted behavior
//int selectedIndex = this.accountsListBox.SelectedIndex;
//this.accountsListBox.UpdateLayout();
//this.accountsListBox.ScrollIntoView(this.accountsListBox.Items[this.accountsListBox.SelectedIndex - 4]);
//this.accountsListBox.SelectedIndex = selectedIndex;
}
}
這是exactally權的高度年底追加!感謝看到我沒有。 – Aligned 2010-08-18 21:42:47