I created a favorite list box where the user can save text from Textblock
in MainPage.xaml
You can check for duplicates quite easily using a LINQ Any
query at the beginning of the FavoriteButton_Click
method:
private void FavoriteButton_Click( object sender, RoutedEventArgs e )
{
//check if there is any item with the same text
//in which case do not continue
if ( listobj.Any( l => l.AnswerName == AnswerTextBlock.Text ) ) return;
listobj.Add( new MyData { AnswerName = AnswerTextBlock.Text } );
using ( IsolatedStorageFileStream fileStream = Settings1.OpenFile( "MyStoreItems", FileMode.Create ) )
{
DataContractSerializer serializer = new DataContractSerializer( typeof( MyDataList ) );
serializer.WriteObject( fileStream, listobj );
}
}