Beispiel #1
0
        /// <summary>
        ///     Converts from a <see cref="ExtendedToolBarButton"/> to an image source.
        ///     Uses the reference from <paramref name="command"/> first, and if null uses the <paramref name="reference"/> object.
        /// <returns>
        ///     If both are null, returns null.
        /// </returns>
        /// </summary>
        private static ImageSource GetItemImageSource(ICommand command, CommandResourceReference reference)
        {
            ImageSource ItemImageSource = null;

            ExtendedRoutedCommand AsExtendedCommand;
            RoutedUICommand       AsUICommand;

            if ((AsExtendedCommand = command as ExtendedRoutedCommand) != null)
            {
                ItemImageSource = AsExtendedCommand.ImageSource;
            }

            else if ((AsUICommand = command as RoutedUICommand) != null)
            {
                if (reference != null)
                {
                    Assembly ReferenceAssembly = Assembly.Load(reference.AssemblyName);
                    if (ReferenceAssembly != null)
                    {
                        ItemImageSource = ThemeIcons.GetImageSource(ReferenceAssembly, AsUICommand.Name);
                    }
                }
            }

            return(ItemImageSource);
        }
Beispiel #2
0
        /// <summary>
        /// Converts from a <see cref="ExtendedToolBarButton"/> to an image source.
        /// Uses the reference from <paramref name="command"/> first, and if null uses the <paramref name="reference"/> object.
        /// <returns>
        /// If both are null, returns null.
        /// </returns>
        /// </summary>
        private static ImageSource GetItemImageSource(ICommand command, CommandResourceReference reference)
        {
            switch (command)
            {
            case ExtendedRoutedCommand AsExtendedCommand:
                return(AsExtendedCommand.ImageSource);

            case RoutedUICommand AsUICommand:
                Assembly    ReferenceAssembly = Assembly.Load(reference.AssemblyName);
                ImageSource ItemImageSource   = ThemeIcons.GetImageSource(ReferenceAssembly, AsUICommand.Name);
                return(ItemImageSource);

            default:
                throw new ArgumentOutOfRangeException(nameof(command));
            }
        }