BetterExplorer.Utilities.Build_MenuItem C# (CSharp) Метод

Build_MenuItem() приватный Метод

private Build_MenuItem ( Object header = null, Object tag = null, Object icon = null, string name = null, object ToolTip = null, bool focusable = true, bool checkable = false, bool isChecked = false, string GroupName = null, System onClick = null ) : Fluent.MenuItem
header Object
tag Object
icon Object
name string
ToolTip object
focusable bool
checkable bool
isChecked bool
GroupName string
onClick System
Результат Fluent.MenuItem
		public static Fluent.MenuItem Build_MenuItem(Object header = null, Object tag = null, Object icon = null, string name = null, object ToolTip = null,
			bool focusable = true, bool checkable = false, bool isChecked = false, string GroupName = null, System.Windows.RoutedEventHandler onClick = null) {

			var Item = new Fluent.MenuItem() {
				Name = name,
				Header = header,
				Tag = tag,
				Focusable = focusable,
				IsCheckable = checkable,
				IsChecked = isChecked,
				Icon = icon,
				GroupName = GroupName,
				ToolTip = ToolTip
			};

			if (onClick != null) Item.Click += onClick;
			return Item;
		} //TODO: Convert this into an extension

Usage Example

Пример #1
0
        /// <summary>
        /// Constructs the copy/move to menu for tabs
        /// </summary>
        private void ConstructMoveToCopyToMenu()
        {
            this.btnMoveto.Items.Clear();
            this.btnCopyto.Items.Clear();

            var sod = FileSystemListItem.ToFileSystemItem(this._ShellListView.LVHandle, ((ShellItem)KnownFolders.Desktop).Pidl);
            var bmpSourceDesktop = sod.ThumbnailSource(16, ShellThumbnailFormatOption.IconOnly, ShellThumbnailRetrievalOption.Default);

            var otherLocationMove = Utilities.Build_MenuItem(this.FindResource("miOtherDestCP"), onClick: new RoutedEventHandler(this.btnmtOther_Click));
            var otherLocationCopy = Utilities.Build_MenuItem(this.FindResource("miOtherDestCP"), onClick: new RoutedEventHandler(this.btnctOther_Click));
            var mimDesktop        = Utilities.Build_MenuItem(this.FindResource("btnctDesktopCP"), icon: bmpSourceDesktop, onClick: new RoutedEventHandler(this.btnmtDesktop_Click));
            var micDesktop        = Utilities.Build_MenuItem(this.FindResource("btnctDesktopCP"), icon: bmpSourceDesktop, onClick: new RoutedEventHandler(this.btnctDesktop_Click));

            MenuItem mimDocuments = new MenuItem(), micDocuments = new MenuItem();

            try {
                var sodc = FileSystemListItem.ToFileSystemItem(this._ShellListView.LVHandle, ((ShellItem)KnownFolders.Documents).Pidl);
                var bmpSourceDocuments = sodc.ThumbnailSource(16, ShellThumbnailFormatOption.IconOnly, ShellThumbnailRetrievalOption.Default);

                mimDocuments = Utilities.Build_MenuItem(this.FindResource("btnctDocumentsCP"), icon: bmpSourceDocuments, onClick: new RoutedEventHandler(this.btnmtDocuments_Click));
                micDocuments = Utilities.Build_MenuItem(this.FindResource("btnctDocumentsCP"), icon: bmpSourceDocuments, onClick: new RoutedEventHandler(this.btnctDocuments_Click));
            }
            catch (Exception) {
                mimDocuments = null;
                micDocuments = null;

                // catch the exception in case the user deleted that basic folder somehow
            }

            MenuItem mimDownloads = new MenuItem(), micDownloads = new MenuItem();

            try {
                var sodd = FileSystemListItem.ToFileSystemItem(this._ShellListView.LVHandle, ((ShellItem)KnownFolders.Downloads).Pidl);
                var bmpSourceDownloads = sodd.ThumbnailSource(16, ShellThumbnailFormatOption.IconOnly, ShellThumbnailRetrievalOption.Default);

                mimDownloads = Utilities.Build_MenuItem(this.FindResource("btnctDownloadsCP"), icon: bmpSourceDownloads, onClick: new RoutedEventHandler(this.btnmtDounloads_Click));
                micDownloads = Utilities.Build_MenuItem(this.FindResource("btnctDownloadsCP"), icon: bmpSourceDownloads, onClick: new RoutedEventHandler(this.btnctDounloads_Click));
            }
            catch (Exception) {
                micDownloads = null;
                mimDownloads = null;

                // catch the exception in case the user deleted that basic folder somehow
            }

            if (mimDocuments != null)
            {
                this.btnMoveto.Items.Add(mimDocuments);
            }

            if (mimDownloads != null)
            {
                this.btnMoveto.Items.Add(mimDownloads);
            }

            this.btnMoveto.Items.Add(mimDesktop);
            this.btnMoveto.Items.Add(new Separator());

            if (micDocuments != null)
            {
                this.btnCopyto.Items.Add(micDocuments);
            }

            if (micDownloads != null)
            {
                this.btnCopyto.Items.Add(micDownloads);
            }

            this.btnCopyto.Items.Add(micDesktop);
            this.btnCopyto.Items.Add(new Separator());

            foreach (var item in this.tcMain.Items.OfType <Wpf.Controls.TabItem>())
            {
                var isAdditem = true;
                item.ShellObject = item.ShellObject.Clone();
                foreach (var mii in this.btnCopyto.Items.OfType <MenuItem>().Where(x => x.Tag != null))
                {
                    if ((mii.Tag as IListItemEx).Equals(item.ShellObject))
                    {
                        isAdditem = false;
                    }
                }

                if (isAdditem && item.ShellObject.IsFileSystem)
                {
                    try {
                        var so        = item.ShellObject;
                        var bmpSource = so.ThumbnailSource(16, ShellThumbnailFormatOption.IconOnly, ShellThumbnailRetrievalOption.Default);
                        this.btnMoveto.Items.Add(Utilities.Build_MenuItem(item.ShellObject.DisplayName, item.ShellObject, bmpSource, onClick: new RoutedEventHandler(this.mim_Click)));
                        this.btnCopyto.Items.Add(Utilities.Build_MenuItem(item.ShellObject.DisplayName, item.ShellObject, bmpSource, onClick: new RoutedEventHandler(this.mico_Click)));
                    }
                    catch {
                        // Do nothing if ShellItem is not available anymore and close the problematic item
                        // tcMain.RemoveTabItem(item);
                    }
                }
            }

            this.btnMoveto.Items.Add(new Separator());
            this.btnMoveto.Items.Add(otherLocationMove);
            this.btnCopyto.Items.Add(new Separator());
            this.btnCopyto.Items.Add(otherLocationCopy);
        }