예제 #1
0
        private static void Item_Expanded(object sender, RoutedEventArgs e)
        {
            var uiElement = sender as TreeViewItem;

            // Sanity check just in case this was somehow send by something else
            if (uiElement == null)
            {
                return;
            }

            ICommand changedCommand = TreeViewItemExpanded.GetCommand(uiElement);

            // There may not be a command bound to this after all
            if (changedCommand == null)
            {
                return;
            }

            // Check whether this attached behaviour is bound to a RoutedCommand
            if (changedCommand is RoutedCommand)
            {
                // Execute the routed command
                (changedCommand as RoutedCommand).Execute(uiElement.DataContext, uiElement);
            }
            else
            {
                // Execute the Command as bound delegate
                changedCommand.Execute(uiElement.DataContext);
            }
        }
예제 #2
0
        private static void Item_Expanded(object sender, RoutedEventArgs e)
        {
            var uiElement = sender as TreeViewItem;

            // Sanity check just in case this was somehow send by something else
            if (uiElement == null)
            {
                return;
            }

            IFolderViewModel f = null;

            if (uiElement.DataContext is KeyValuePair <string, IFolderViewModel> )
            {
                var item = ((KeyValuePair <string, IFolderViewModel>)uiElement.DataContext);

                f = item.Value;

                // Message Expand only for those who have 1 dummy folder below
                if (f.ChildFolderIsDummy == false)
                {
                    return;
                }
            }

            ICommand changedCommand = TreeViewItemExpanded.GetCommand(uiElement);

            // There may not be a command bound to this after all
            if (changedCommand == null || f == null)
            {
                return;
            }

            // Check whether this attached behaviour is bound to a RoutedCommand
            if (changedCommand is RoutedCommand)
            {
                // Execute the routed command
                (changedCommand as RoutedCommand).Execute(f, uiElement);
            }
            else
            {
                // Execute the Command as bound delegate
                changedCommand.Execute(f);
            }
        }