Пример #1
0
        public void RefreshLibraryBrowserNode(LibraryBrowserEntity entity, IEnumerable<LibraryBrowserEntity> entities, object userData)
        {
            //Console.WriteLine("MainWindow - RefreshLibraryBrowserNode - entities.Count: {0}", entities.Count());
            Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
            {
                var item = (LibraryTreeViewItem) userData;
                foreach (var subentity in entities)
                {
                    var subitem = new LibraryTreeViewItem();
                    subitem.Entity = subentity;
                    subitem.Header = subentity;
                    subitem.HeaderTemplate = FindResource("TreeViewItemTemplate") as DataTemplate;

                    if (subentity.SubItems.Count > 0)
                    {
                        var dummy = new LibraryTreeViewItem();                        
                        dummy.IsDummyNode = true;
                        subitem.Items.Add(dummy);
                    }

                    item.Items.Add(subitem);
                }

                if (_selectedLibraryNode != null)
                {
                    switch (entity.EntityType)
                    {
                        case LibraryBrowserEntityType.Artists:
                            var artistNode = GetLibraryTreeViewItemByArtistName(item.Items, _selectedLibraryNode.Query.ArtistName);
                            if (artistNode != null)
                            {
                                if (_selectedLibraryNode.EntityType == LibraryBrowserEntityType.Artist)
                                {
                                    artistNode.IsSelected = true;
                                    artistNode.BringIntoView();
                                    _selectedLibraryNode = null;
                                }
                                else if (_selectedLibraryNode.EntityType == LibraryBrowserEntityType.ArtistAlbum)
                                {
                                    artistNode.IsExpanded = true;
                                    artistNode.BringIntoView();
                                }
                            }
                            break;
                        case LibraryBrowserEntityType.Artist:
                            var artistAlbumNode = GetLibraryTreeViewItemByAlbumTitle(item.Items, _selectedLibraryNode.Query.AlbumTitle);
                            if (artistAlbumNode != null)
                            {
                                artistAlbumNode.IsSelected = true;
                                artistAlbumNode.BringIntoView(); //new Rect(0, treeViewLibrary.ScrollViewer.VerticalOffset, 10, 10));
                            }
                            _selectedLibraryNode = null;
                            break;
                        case LibraryBrowserEntityType.Albums:
                            var albumNode = GetLibraryTreeViewItemByAlbumTitle(item.Items, _selectedLibraryNode.Query.AlbumTitle);
                            if (albumNode != null)
                            {
                                albumNode.IsSelected = true;
                                albumNode.BringIntoView();
                            }
                            _selectedLibraryNode = null;
                            break;
                    }
                }

                // When calling BringIntoView, the horizontal offset is not always zero. 
                // This is a workaround, BringIntoView(Rect) doesn't seem to work...
                treeViewLibrary.ScrollViewer.ScrollToHorizontalOffset(0);
            }));
        }
Пример #2
0
        public void RefreshLibraryBrowser(IEnumerable<LibraryBrowserEntity> entities)
        {
            //Console.WriteLine("MainWindow - RefreshLibraryBrowser - entities.Count: {0}", entities.Count());
            Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
            {
                treeViewLibrary.Items.Clear();
                foreach (var entity in entities)
                {
                    var item = new LibraryTreeViewItem();
                    //item.Expanding += (sender, args) => { Console.WriteLine("Expanding"); };
                    item.Entity = entity;
                    item.Header = entity;
                    item.HeaderTemplate = FindResource("TreeViewItemTemplate") as DataTemplate;

                    if (entity.SubItems.Count > 0)
                    {
                        var dummy = new LibraryTreeViewItem();
                        dummy.IsDummyNode = true;
                        item.Items.Add(dummy);
                    }

                    treeViewLibrary.Items.Add(item);
                }
            }));
        }