Esempio n. 1
0
        private void GridRow_ContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            DependencyObject dep = e.OriginalSource as DependencyObject;

            while ((dep != null) && !(dep is ContentPresenter))
            {
                dep = VisualTreeHelper.GetParent(dep);
            }

            SelectedAlbum = null;
            SelectedTrack = null;

            ContentPresenter cp = dep as ContentPresenter;

            if (cp != null)
            {
                if (cp.DataContext is Track)
                {
                    SelectedTrack = cp.DataContext as Track;
                }
                else
                {
                    AlbumViewItem item = dataGrid1.ItemContainerGenerator.ItemFromContainer(dep) as AlbumViewItem;
                    SelectedAlbum = item;
                }
                if ((SelectedAlbum != null || SelectedTrack != null) && OpenContextMenu != null)
                {
                    OpenContextMenu(sender, e);
                }
            }
        }
Esempio n. 2
0
        private bool FilterRow(object row)
        {
            if (string.IsNullOrEmpty(FilterString))
            {
                return(true);
            }

            string filterString = FilterString.ToLower();

            bool found = false;

            AlbumViewItem avi = row as AlbumViewItem;

            if (avi.Artist != null && avi.Artist.ToLower().IndexOf(filterString) >= 0)
            {
                return(true);
            }
            if (avi.Title != null && avi.Title.ToLower().IndexOf(filterString) >= 0)
            {
                return(true);
            }
            if (avi.Genre != null && avi.Genre.ToLower().IndexOf(filterString) >= 0)
            {
                return(true);
            }
            if (avi.Year != null && avi.Year.ToLower().IndexOf(filterString) >= 0)
            {
                return(true);
            }
            foreach (Track t in avi.Tracks)
            {
                if (t.Artist != null && t.Artist.ToLower().IndexOf(filterString) >= 0)
                {
                    found = true;
                    break;
                }
                if (t.Title != null && t.Title.ToLower().IndexOf(filterString) >= 0)
                {
                    found = true;
                    break;
                }
            }

            return(found);
        }
Esempio n. 3
0
        private void GridRow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            DependencyObject dep = e.OriginalSource as DependencyObject;

            while ((dep != null) && !(dep is ContentPresenter))
            {
                dep = VisualTreeHelper.GetParent(dep);
            }

            AlbumViewItem item = dataGrid1.ItemContainerGenerator.ItemFromContainer(dep) as AlbumViewItem;

            SelectedAlbum = item;

            if (SelectionChanged != null)
            {
                SelectionChanged(sender, new EventArgs());
            }
        }
        // I've isolated the layout specific code to this region. If you want to do something other than tiling, this is
        // where you'll make your changes

        /// <summary>
        /// Calculate the extent of the view based on the available size
        /// </summary>
        /// <param name="availableSize">available size</param>
        /// <param name="itemCount">number of data items</param>
        /// <returns></returns>
        private Size CalculateExtent(Size availableSize)
        {
            if (totalHeight > 0)
            {
                return(new Size(availableSize.Width, totalHeight));
            }
            // Die Gesamtgröße der Liste berechnen.
            ItemsControl itemsControl = ItemsControl.GetItemsOwner(this);

            // We need to access InternalChildren before the generator to work around a bug
            UIElementCollection     children  = this.InternalChildren;
            IItemContainerGenerator generator = this.ItemContainerGenerator;

            // Get the generator position of the first visible data item
            GeneratorPosition startPos = generator.GeneratorPositionFromIndex(0);

            using (generator.StartAt(startPos, GeneratorDirection.Forward, true))
            {
                for (int itemIndex = 0; itemIndex < itemsControl.Items.Count; ++itemIndex)
                {
                    itemsTopPosition.Add(totalHeight);

                    // Get or create the child
                    bool      newlyRealized;
                    UIElement child = generator.GenerateNext(out newlyRealized) as UIElement;

                    generator.PrepareItemContainer(child);

                    // Measurements will depend on layout algorithm
                    //child.Measure(GetChildSize());
                    AlbumViewItem avi    = itemsControl.Items[itemIndex] as AlbumViewItem;
                    double        height = Math.Max((avi.Tracks.Count * 18) + 10, 150);
                    totalHeight += height;
                    itemsHeight.Add(height);
                }
            }

            generator.RemoveAll();

            // See how big we are
            return(new Size(this.ActualWidth, totalHeight));
        }
Esempio n. 5
0
        void bwAlbumView_DoWork(object sender, DoWorkEventArgs e)
        {
            TrackDataView TrackView;

            CDQuery = DataBase.ExecuteTrackQuery();

            // Hier die Felder auflisten, die ich für die Albumansicht brauche
            FieldCollection fc = new FieldCollection();

            fc.AddRange(new Field[] {
                Field.ArtistCDName,
                Field.ArtistCDSaveAs,
                Field.Title,
                Field.CDCoverFront,
                Field.Category,
                Field.ArchiveNumber,
                Field.YearRecorded,
                Field.TrackNumber,
                Field.TrackTitle,
                Field.TrackLength,
                Field.TrackRating,
                Field.ArtistTrackName,
                Field.ComposerTrackName,
                Field.TrackSoundFile
            });

            SortFieldCollection sfc = new SortFieldCollection();

            sfc.Add(Field.ArtistCDSaveAs);
            sfc.Add(Field.Title);
            sfc.Add(Field.CDID);
            sfc.Add(Field.TrackNumber);
            TrackView = new TrackDataView(DataBase, CDQuery, Condition, sfc, fc);

            int count = 0;

            List <AlbumViewItem> items = new List <AlbumViewItem>();

            AlbumViewItem newItem    = null;
            string        lastArtist = "";
            string        lastTitle  = "";
            int           lastcdid   = 0;

            for (int row = 0; row < TrackView.Rows.Count; row++)
            {
                string artistDisplay = TrackView.GetRowStringValue(row, Field.ArtistCDName);
                string artist        = TrackView.GetRowStringValue(row, Field.ArtistCDSaveAs);
                string title         = TrackView.GetRowStringValue(row, Field.Title);
                int    cdid          = TrackView.GetCDID(row);

                if (artist != lastArtist || title != lastTitle || cdid != lastcdid)
                {
                    if (newItem != null)
                    {
                        items.Add(newItem);
                    }

                    newItem               = new AlbumViewItem();
                    newItem.ID            = cdid;
                    newItem.Artist        = artistDisplay;
                    newItem.Title         = title;
                    newItem.ImageFilename = TrackView.GetRowStringValue(row, Field.CDCoverFront);
                    newItem.Genre         = TrackView.GetRowStringValue(row, Field.Category);
                    newItem.ArchiveNumber = TrackView.GetRowStringValue(row, Field.ArchiveNumber);
                    int yearRecorded = (int)TrackView.GetRowRawValue(row, Field.YearRecorded);
                    if (yearRecorded > 0)
                    {
                        newItem.Year = yearRecorded.ToString();
                    }

                    newItem.Tracks = new List <Track>();
                    lastArtist     = artist;
                    lastTitle      = title;
                }

                if (newItem != null)
                {
                    Track track = new Track();
                    track.TrackNumber = (int)TrackView.GetRowRawValue(row, Field.TrackNumber);
                    track.Title       = TrackView.GetRowStringValue(row, Field.TrackTitle);
                    track.Length      = (int)TrackView.GetRowRawValue(row, Field.TrackLength);
                    track.Rating      = (int)TrackView.GetRowRawValue(row, Field.TrackRating);
                    track.Artist      = TrackView.GetRowStringValue(row, Field.ArtistTrackName);
                    track.Composer    = TrackView.GetRowStringValue(row, Field.ComposerTrackName);
                    track.Soundfile   = TrackView.GetRowStringValue(row, Field.TrackSoundFile);
                    track.ID          = TrackView.GetTrackID(row);

                    newItem.Tracks.Add(track);
                }

                //toolStripStatusProgressBar.Value = (int)(100.0 / TrackView.Rows.Count * count);

                count++;

                lastcdid = cdid;
            }

            if (newItem != null)
            {
                items.Add(newItem);
            }

            e.Result = items;
        }