コード例 #1
0
ファイル: ShowView.xaml.cs プロジェクト: entrotech/talent
 private void GenresEditButton_Click(object sender, RoutedEventArgs e)
 {
     var show = DataContext as Show;
     if (show == null) return;
     var dlg = new GenrePicker();
     dlg.SelectedGenreIds = show.ShowGenres
         .Where(o => o.IsMarkedForDeletion == false)
         .Select(o => o.GenreId).ToList();
     if (dlg.ShowDialog() == true)
     {
         var selectedGenreIds = dlg.SelectedGenreIds;
         foreach (var sgid in selectedGenreIds)
         {
             var showGenre = show.ShowGenres.Where(o => o.GenreId == sgid).FirstOrDefault();
             if (showGenre == null)
             {
                 show.ShowGenres.Add(new ShowGenre { GenreId = sgid });
             }
             else
             {
                 showGenre.IsMarkedForDeletion = false;
             }
         }
         var showGenresToDelete = show.ShowGenres.Where(o => !selectedGenreIds.Contains(o.GenreId));
         foreach (var sg in showGenresToDelete)
         {
             sg.IsMarkedForDeletion = true;
         }
         // Force an update to the GenresTextBox binding
         // This is necessary because the TextBox does not listen for
         // INotifyCollectionChanged events.
         BindingOperations.GetBindingExpression(GenresTextBox, TextBox.TextProperty)
             .UpdateTarget();
     }
 }
コード例 #2
0
        private void GenresEditButton_Click(object sender, RoutedEventArgs e)
        {
            var vm = DataContext as ShowsViewModel;

            if (vm == null)
            {
                return;
            }
            var show = vm.SelectedItem as Show;
            var dlg  = new GenrePicker();

            dlg.SelectedGenreIds = show.ShowGenres
                                   .Where(o => o.IsMarkedForDeletion == false)
                                   .Select(o => o.GenreId).ToList();
            if (dlg.ShowDialog() == true)
            {
                var hasChanges       = false;
                var selectedGenreIds = dlg.SelectedGenreIds;
                foreach (var sgid in selectedGenreIds)
                {
                    var showGenre = show.ShowGenres.Where(o =>
                                                          o.GenreId == sgid).FirstOrDefault();
                    if (showGenre == null)
                    {
                        show.ShowGenres.Add(new ShowGenre {
                            GenreId = sgid
                        });
                        hasChanges = true;
                    }
                    else
                    {
                        showGenre.IsMarkedForDeletion = false;
                    }
                }
                var showGenresToDelete = show.ShowGenres.Where(o =>
                                                               !selectedGenreIds.Contains(o.GenreId));
                foreach (var sg in showGenresToDelete)
                {
                    sg.IsMarkedForDeletion = true;
                    hasChanges             = true;
                }
                // Force an update to the GenresTextBox binding
                // This is necessary because the TextBox does not listen for
                // INotifyCollectionChanged events.
                BindingOperations.GetBindingExpression(GenresTextBox, TextBox.TextProperty)
                .UpdateTarget();
                if (hasChanges)
                {
                    ((DomainViewModel <Show>)DataContext).SelectedItem.IsDirty = true;
                }
            }
        }