Exemplo n.º 1
0
        /// <summary>
        /// This method creates a ListViewItem based on a given IListableItem
        /// </summary>
        /// <param name="item">The item to generate a ListViewItem for.</param>
        /// <returns>The created ListViewItem.</returns>
        private ListViewItem CreateListViewItem(IListableItem item)
        {
            StackPanel sp = new StackPanel()
            {
                Width = 50, Height = 50, Orientation = Orientation.Vertical, IsHitTestVisible = false
            };

            sp.Children.Add(new Image()
            {
                Source = item.GetIcon(), Width = 24, Height = 24
            });
            sp.Children.Add(new Label()
            {
                Content = item.Title, MaxWidth = 50, HorizontalAlignment = HorizontalAlignment.Center
            });
            ListViewItem listViewItem = new ListViewItem()
            {
                Margin = new Thickness(2)
            };

            listViewItem.Content           = sp;
            listViewItem.Tag               = item;
            listViewItem.MouseDoubleClick += new MouseButtonEventHandler(
                (sender, e) => OnItemDoubleClicked(new ListableItemEventArgs((sender as ListViewItem).Tag as IListableItem)) //fire own event
                );
            return(listViewItem);
        }
 /// <summary>
 /// This method creates a ListViewItem based on a given IListableItem
 /// </summary>
 /// <param name="item">The item to generate a ListViewItem for.</param>
 /// <returns>The created ListViewItem.</returns>
 private ListViewItem CreateListViewItem(IListableItem item)
 {
     StackPanel sp = new StackPanel() { Width = 50, Height = 50, Orientation = Orientation.Vertical, IsHitTestVisible = false };
     sp.Children.Add(new Image() { Source = item.GetIcon(), Width = 24, Height = 24 });
     sp.Children.Add(new Label() { Content = item.Title, MaxWidth = 50, HorizontalAlignment = HorizontalAlignment.Center });
     ListViewItem listViewItem = new ListViewItem() { Margin = new Thickness(2) };
     listViewItem.Content = sp;
     listViewItem.Tag = item;
     listViewItem.MouseDoubleClick += new MouseButtonEventHandler(
         (sender, e) => OnItemDoubleClicked(new ListableItemEventArgs((sender as ListViewItem).Tag as IListableItem)) //fire own event
     );
     return listViewItem;
 }
Exemplo n.º 3
0
        /// <summary>
        /// This is a helper method for creating a  item in the item explorer.
        /// </summary>
        /// <param name="item">The IListableItem to associate with the TreeViewItem.</param>
        /// <returns>The created TreeViewItem.</returns>
        private TreeViewItem CreateTreeViewItem(IListableItem item)
        {
            TreeViewItem thisTreeViewItem = new TreeViewItem()
            {
                Tag = item
            };
            //StackPanel for image and text block
            StackPanel sp = new StackPanel()
            {
                Orientation = Orientation.Horizontal, IsHitTestVisible = false
            };
            //Create the image
            Image image = new Image()
            {
                Source = item.GetIcon(), Height = 15, Width = 15
            };

            sp.Children.Add(image);
            //Create the text block
            TextBlock itemText = new TextBlock()
            {
                Text = item.Title, Margin = new Thickness(5, 0, 0, 0), IsHitTestVisible = false
            };

            sp.Children.Add(itemText);
            thisTreeViewItem.Header = sp;
            //set up event handlers
            thisTreeViewItem.MouseDoubleClick += new MouseButtonEventHandler((sender, e) => e.Handled = true); /*This User Control does not provide any double click behaviour - not even the default of TreeViewItems.
                                                                                                                * This is a design choice. We provide a MouseLeftButtonUp instead - having both would cause conflicting behaviour.
                                                                                                                * (The MouseEventArgs.Count property cannot be used as one would expect, since it's keyUp vs. 2 x keyDown).
                                                                                                                * Similar rejections of event bubbling in this TreeViewItem will be found in the methods below (TreeViewItem has a few unwanted default events)   */

            thisTreeViewItem.MouseLeftButtonUp += new MouseButtonEventHandler((sender, e) => {
                e.Handled = true;
                thisTreeViewItem.IsSelected = true;
                thisTreeViewItem.IsExpanded = true;
                OnItemMouseLeftButtonUp(new ListableItemEventArgs(item));
            });

            thisTreeViewItem.MouseRightButtonDown += new MouseButtonEventHandler((sender, e) => { e.Handled = true; thisTreeViewItem.IsSelected = true; });  //selected for visual feedback in line with our LeftMouseButtonDown.

            thisTreeViewItem.MouseRightButtonUp += new MouseButtonEventHandler((sender, e) => { e.Handled = true; OnItemMouseRightButtonUp(new ListableItemEventArgs(item)); });

            thisTreeViewItem.KeyUp += new KeyEventHandler((sender, e) => {
                if (e.Key.Equals(System.Windows.Input.Key.Enter))
                {
                    e.Handled = true;
                    thisTreeViewItem.IsSelected = true;
                    thisTreeViewItem.IsExpanded = true;
                    OnItemEnterKeyUp(new ListableItemEventArgs(item));
                }
            });

            //recursive traversal of structure for Item Containers
            if (item is IItemContainer)
            {
                //First add folders
                foreach (Folder folder in (item as IItemContainer).GetFolders())
                {
                    thisTreeViewItem.Items.Add(CreateTreeViewItem(folder));
                }
                //then documents
                foreach (Document document in (item as IItemContainer).GetDocuments())
                {
                    thisTreeViewItem.Items.Add(CreateTreeViewItem(document));
                }
            }
            return(thisTreeViewItem);
        }
Exemplo n.º 4
0
        /// <summary>
        /// This is a helper method for creating a  item in the item explorer.
        /// </summary>
        /// <param name="item">The IListableItem to associate with the TreeViewItem.</param>
        /// <returns>The created TreeViewItem.</returns>
        private TreeViewItem CreateTreeViewItem(IListableItem item)
        {
            TreeViewItem thisTreeViewItem = new TreeViewItem() { Tag = item };
            //StackPanel for image and text block
            StackPanel sp = new StackPanel() { Orientation = Orientation.Horizontal, IsHitTestVisible = false };
            //Create the image
            Image image = new Image() { Source = item.GetIcon(), Height = 15, Width = 15 };
            sp.Children.Add(image);
            //Create the text block
            TextBlock itemText = new TextBlock() { Text = item.Title, Margin = new Thickness(5, 0, 0, 0), IsHitTestVisible = false };
            sp.Children.Add(itemText);
            thisTreeViewItem.Header = sp;
            //set up event handlers
            thisTreeViewItem.MouseDoubleClick += new MouseButtonEventHandler((sender, e) => e.Handled = true); /*This User Control does not provide any double click behaviour - not even the default of TreeViewItems.
                                                                                                              * This is a design choice. We provide a MouseLeftButtonUp instead - having both would cause conflicting behaviour.
                                                                                                              * (The MouseEventArgs.Count property cannot be used as one would expect, since it's keyUp vs. 2 x keyDown).
                                                                                                              * Similar rejections of event bubbling in this TreeViewItem will be found in the methods below (TreeViewItem has a few unwanted default events)   */

            thisTreeViewItem.MouseLeftButtonUp += new MouseButtonEventHandler((sender, e) => {
                e.Handled = true;
                thisTreeViewItem.IsSelected = true;
                thisTreeViewItem.IsExpanded = true;
                OnItemMouseLeftButtonUp(new ListableItemEventArgs(item));
            });

            thisTreeViewItem.MouseRightButtonDown += new MouseButtonEventHandler((sender, e) => { e.Handled = true; thisTreeViewItem.IsSelected = true; });  //selected for visual feedback in line with our LeftMouseButtonDown.

            thisTreeViewItem.MouseRightButtonUp += new MouseButtonEventHandler((sender, e) => { e.Handled = true; OnItemMouseRightButtonUp(new ListableItemEventArgs(item)); });

            thisTreeViewItem.KeyUp += new KeyEventHandler((sender, e) => {
                if (e.Key.Equals(System.Windows.Input.Key.Enter)) {
                    e.Handled = true;
                    thisTreeViewItem.IsSelected = true;
                    thisTreeViewItem.IsExpanded = true;
                    OnItemEnterKeyUp(new ListableItemEventArgs(item));
                }
            });

            //recursive traversal of structure for Item Containers
            if (item is IItemContainer) {
                //First add folders
                foreach (Folder folder in (item as IItemContainer).GetFolders()) {
                    thisTreeViewItem.Items.Add(CreateTreeViewItem(folder));
                }
                //then documents
                foreach (Document document in (item as IItemContainer).GetDocuments()) {
                    thisTreeViewItem.Items.Add(CreateTreeViewItem(document));
                }
            }
            return thisTreeViewItem;
        }