Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 列表框滚动到wp7中结束_C#_Silverlight_Windows Phone 7_Xaml_Silverlight Toolkit - Fatal编程技术网

C# 列表框滚动到wp7中结束

C# 列表框滚动到wp7中结束,c#,silverlight,windows-phone-7,xaml,silverlight-toolkit,C#,Silverlight,Windows Phone 7,Xaml,Silverlight Toolkit,我的wp7应用程序中有这样的列表框 <ListBox Name="lstSelectedNumber" Height="50" MaxHeight="120" VerticalAlignment="Top" Grid.Column="1" SelectionChanged="lstSelectedNumber_SelectionChanged"> <ListBox.ItemContainerStyle>

我的wp7应用程序中有这样的列表框

   <ListBox Name="lstSelectedNumber" Height="50" MaxHeight="120" VerticalAlignment="Top" Grid.Column="1" SelectionChanged="lstSelectedNumber_SelectionChanged">
                            <ListBox.ItemContainerStyle>
                                <Style TargetType="ListBoxItem">
                                    <Setter Property="Padding" Value="-15" />
                                    <Setter Property="Margin" Value="0"/>
                                </Style>
                            </ListBox.ItemContainerStyle>
                            <ListBox.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <toolkit:WrapPanel>
                                    </toolkit:WrapPanel>
                                </ItemsPanelTemplate>
                            </ListBox.ItemsPanel>
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel>
                                    <TextBox x:Name="txtNumber" Text="{Binding Name,Mode=TwoWay}" IsEnabled="{Binding IsEnabled,Mode=TwoWay}" Background="Transparent" Foreground="{StaticResource ContactSelectorBrush}" Style="{StaticResource DialNumberStyle}" FontSize="24" KeyUp="txtNumber_KeyUp">
                                        <TextBox.CaretBrush>
                                            <SolidColorBrush Color="{StaticResource CaretBrush}" />
                                        </TextBox.CaretBrush>
                                    </TextBox>
                                    </StackPanel>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
TextBox txtbox = sender as TextBox;
                Dispatcher.BeginInvoke(() =>
                {
                    ContactModel model = lstContactModel.LastOrDefault();
                    if (string.IsNullOrEmpty(model.Name) && string.IsNullOrEmpty(model.Phone))
                    {
                        lstContactModel.Remove(model);
                        lstContactModel.Add(new ContactModel { Name = txtbox.Text, Phone = txtbox.Text + ",", IsEnabled = false });
                    }

                    lstSelectedNumber.ItemsSource = null;
                    lstSelectedNumber.ItemsSource = lstContactModel;
                    var Selecteditem = lstSelectedNumber.Items[lstSelectedNumber.Items.Count - 1];
                    lstSelectedNumber.ScrollIntoView(Selecteditem);
                    lstSelectedNumber.UpdateLayout();
                });
我将新项目添加到列表中,然后重新绑定到我的列表框,我将滚动到列表框的末尾,但它不起作用


它表现出非常奇怪的行为。此语句运行后,它将添加该项,并将焦点转到不在此列表框中的另一个文本框(它是我的wp7页面中的下一个控件)。有人能指出其中的错误吗?

您删除
项资源并重新设置它是否有原因。

我建议使用
可观察的集合
,让
数据绑定
引擎发挥它的魔力。

我没有使用wolfgang ziegler任何可观察的集合。我使用的是简单的通用集合列表。
lstbox.Dispatcher.BeginInvoke(() =>
                {
                    lstbox.ItemsSource = null;
                    lstbox.ItemsSource = lstContactModel;
                    var Selecteditem = lstbox.Items[lstbox.Items.Count - 1];
                    lstbox.ScrollIntoView(Selecteditem);
                    lstbox.UpdateLayout();
                });