我有一个列表框和一个文本框。我想处理它的 keyup 事件,但它给了我一个错误。
<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>
private void txtNumber_KeyUp(object sender, KeyEventArgs e)
{
TextBox txtbox = sender as TextBox;
if (txtbox.Text.Contains(';'))
{
lstSelectedNumber.ItemsSource = null;
// My Application Got crashed at this point when i assign nullto item source
lstSelectedNumber.ItemsSource = lstContactModel;
}
是否有任何替代我更新的集合是该列表框的 itemsource。请告诉我任何解决方法。