I have a listbox and a textbox. I want to handle its keyup event but its giving me an error.
<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;
}
Is there any alternate that my updated collection is itemsource of that listbox. please tell me any work around for that.
I Have Fixed This Issue Myself.
The Problem is This When My textbox Event is Called It Do Some Changes in My List And Bind Empty Source To My Listbox And This Change Effects My UI And UI Is Unable To Handle That Change So I Put My All Code In Dispatcher So Once All The Things Are Done It Reflects Changes To UI and UI Accepts That