Beispiel #1
0
        /// <summary>
        /// Obtains an image resource from a resource key</summary>
        /// <param name="value">Image resource ID</param>
        /// <returns>Image resource</returns>
        /// <remarks>This method is a workaround for a WPF bug (Fixed in .NET 4).
        /// that prevents binding a MenuItem.Icon to an ImageSource correctly! For details, see
        /// https://connect.microsoft.com/VisualStudio/feedback/details/497408/wpf-menuitem-icon-cannot-be-set-via-setter?wa=wsignin1.0 </remarks>
        public static object Convert(object value)
        {
            if (value == null)
            {
                return(null);
            }

            var    resourceKey = new ComponentResourceKey(typeof(ImageResourceLookupConverter), value);
            object image       = Application.Current.TryFindResource(resourceKey);

            if (image == null)
            {
                var imageSource = Application.Current.TryFindResource(value) as ImageSource;
                if (imageSource != null)
                {
                    var newImage = new Image();
                    newImage.Source = imageSource;
                    newImage.Style  = Application.Current.FindResource(Resources.MenuItemImageStyleKey) as Style;
                    Application.Current.Resources.Add(resourceKey, newImage);
                    image = newImage;
                }
            }

            return(image);
        }
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] HeadingBlock obj)
        {
            var paragraph = new Paragraph();
            ComponentResourceKey styleKey = null;

            switch (obj.Level)
            {
            case 1: styleKey = Styles.Heading1StyleKey; break;

            case 2: styleKey = Styles.Heading2StyleKey; break;

            case 3: styleKey = Styles.Heading3StyleKey; break;

            case 4: styleKey = Styles.Heading4StyleKey; break;

            case 5: styleKey = Styles.Heading5StyleKey; break;

            case 6: styleKey = Styles.Heading6StyleKey; break;
            }

            if (styleKey != null)
            {
                paragraph.SetResourceReference(FrameworkContentElement.StyleProperty, styleKey);
            }

            renderer.Push(paragraph);
            renderer.WriteLeafInline(obj);
            renderer.Pop();
        }
Beispiel #3
0
        /// <summary>
        /// Loads the theme specified and merge it to the specified ResourceDictionary
        /// specifing if the destination ResourceDictionary should be reinitialized
        /// </summary>
        /// <param name="theme">The Theme to be loaded</param>
        /// <param name="destination">The ReourceDictionary where the theme dhata should be merged</param>
        /// <param name="reinitDestination">true to reinitialize the destination ResourceDictionary</param>
        public static void SetActiveTheme(NavigationPaneTheme theme, ResourceDictionary destination, bool reinitDestination)
        {
            Application.Current.Dispatcher.BeginInvoke(
                (ChangeTheme)((t, d, reinit) =>
            {
                bool merge = true;
                Uri dictSource = GetThemeUri(theme);
                foreach (ResourceDictionary dict in d.MergedDictionaries)
                {
                    if (dict.Source != null && dict.Source.Equals(dictSource))  // microsoft blend inject resource without source... so we check it !
                    {
                        merge = false;
                        break;
                    }
                }

                if (merge)
                {
                    d.BeginInit();
                    for (int j = d.MergedDictionaries.Count - 1; j >= 0; j--)
                    {
                        ComponentResourceKey NameRes = new ComponentResourceKey(typeof(NavigationPane), "ActiveTheme");
                        if (d.MergedDictionaries[j].Contains(NameRes))
                        {
                            d.MergedDictionaries.Remove(d.MergedDictionaries[j]);
                        }
                    }
                    d.MergedDictionaries.Add(new ResourceDictionary {
                        Source = dictSource
                    });
                    d.EndInit();
                }
            }
                              ), DispatcherPriority.ApplicationIdle, theme, destination, reinitDestination);
        }
        /// <summary>
        /// Content measurement.
        /// </summary>
        /// <param name="availableSize">Available size that parent can give to the child. This is soft constraint.</param>
        /// <returns>The DocumentGridPage's desired size.</returns>
        protected override sealed Size MeasureOverride(Size availableSize)
        {
            CheckDisposed();

            if (!hasAddedChildren)
            {
                this.AddVisualChild(_documentContainer);

                hasAddedChildren = true;
            }

            //Show / hide the border and drop shadow based on the current
            //state of the ShowPageBorders property.
            if (ShowPageBorders)
            {
                var key = new ComponentResourceKey(typeof(FrameworkElement), "DocumentGridPageContainerWithBorder");
                _documentContainer.SetCurrentValue(StyleProperty, TryFindResource(key));
            }
            else
            {
                _documentContainer.SetCurrentValue(StyleProperty, TryFindResource(typeof(ContentControl)));
            }

            //Measure our children.
            _documentContainer.Measure(availableSize);

            //Set the Page Zoom on the DocumentPageView to the ratio between our measure constraint
            //and the actual size of the page; this will cause the DPV to scale our page appropriately.
            if (DocumentPage.Size != Size.Empty && DocumentPage.Size.Width != 0.0)
            {
                _documentPageView.SetPageZoom(availableSize.Width / DocumentPage.Size.Width);
            }

            return(availableSize);
        }
 public I18nStringExtension(ComponentResourceKey key, object item0, object item1, object item2)
     : this(key)
 {
     Args.Add(item0);
     Args.Add(item1);
     Args.Add(item2);
 }
Beispiel #6
0
 static RectangleSelectionGesture()
 {
     _DefaultSelectionVisualStyle = new Style();
     _DefaultSelectionVisualStyle.Setters.Add(new Setter(Shape.StrokeProperty, Brushes.Blue));
     _DefaultSelectionVisualStyle.Setters.Add(new Setter(Shape.FillProperty, new SolidColorBrush(Color.FromArgb(66, 0, 0, 255))));
     SelectionVisualStyleKey = new ComponentResourceKey(typeof(RectangleSelectionGesture), "SelectionVisualStyle");
 }
        private static DataTemplate TryToFindDataTemplate(FrameworkElement element, Type type)
        {
            var key = new ComponentResourceKey(typeof(PropertyEditor), type);

            // todo: this command throws an exception
            return(element.TryFindResource(key) as DataTemplate);
        }
        public static void LoadVsStyles()
        {
            var assembly = AppDomain.CurrentDomain.Load(
                "Microsoft.VisualStudio.ExtensionsExplorer.UI");
            var comboBoxType = assembly.GetType(
                "Microsoft.VisualStudio.ExtensionsExplorer.UI.AutomationComboBox");

            ThemedComboStyleKey = new ComponentResourceKey(comboBoxType, "ThemedComboBoxStyle");
        }
Beispiel #9
0
        public Painter()
        {
            InitializeComponent();

            // MyEllipseBrush is a theme level resource so it has a ComponentResourceKey.
            ComponentResourceKey brushKey = new ComponentResourceKey(typeof(Painter), "MyEllipseBrush");

            ellipseBrush = (Brush)this.TryFindResource(brushKey);
        }
        public I18nSource(ComponentResourceKey key, FrameworkElement element = null)
        {
            _key = key;

            if (element != null)
            {
                element.Loaded   += OnLoaded;
                element.Unloaded += OnUnloaded;
            }
        }
		private static DataTemplate TryFindDataTemplate(FrameworkElement element, object dataTemplateKey)
		{
			object dataTemplate = element.TryFindResource(dataTemplateKey);
			if (dataTemplate == null)
			{
				dataTemplateKey = new ComponentResourceKey(typeof(PropertyGrid), dataTemplateKey);
				dataTemplate = element.TryFindResource(dataTemplateKey);
			}
			return dataTemplate as DataTemplate;
		}
Beispiel #12
0
 /// <summary>
 /// Return ResourceKey from resourceId
 /// </summary>
 /// <param name="resKey"></param>
 /// <param name="resourceId"></param>
 /// <returns></returns>
 private static ComponentResourceKey GetRegisteredKey(ComponentResourceKey resKey, string resourceId)
 {
     if (resKey == null)
     {
         return(new ComponentResourceKey(typeof(ResourceKeys), resourceId));
     }
     else
     {
         return(resKey);
     }
 }
 private I18nStringExtension(ComponentResourceKey key)
     : this()
 {
     Key = key;
     Bindings.Add(new Binding(nameof(I18nSource.Value))
     {
         Source    = new I18nSource(key),
         Mode      = BindingMode.OneWay,
         Converter = ResourceConverter
     });
 }
Beispiel #14
0
        public void AcceptsResourceKeyForTemplates()
        {
            ComponentResourceKey key = new ComponentResourceKey();
            Editor editor            = new TypeEditor {
                InlineTemplate = key, ExtendedTemplate = key, DialogTemplate = key
            };

            Assert.AreEqual(key, editor.InlineTemplate);
            Assert.AreEqual(key, editor.ExtendedTemplate);
            Assert.AreEqual(key, editor.DialogTemplate);
        }
Beispiel #15
0
 private static void EnsureResource([NotNull] string resourceName, ref ComponentResourceKey resourceKey)
 {
     if (string.IsNullOrEmpty(resourceName))
     {
         throw new ArgumentException("Argument cannot be null or empty.", "resourceName");
     }
     if (resourceKey != null)
     {
         return;
     }
     resourceKey = new ComponentResourceKey(typeof(ClientResources), resourceName);
 }
 public I18nStringExtension(ComponentResourceKey key, object item0, object item1, object item2, object item3, object item4, object item5, object item6, object item7)
     : this(key)
 {
     Args.Add(item0);
     Args.Add(item1);
     Args.Add(item2);
     Args.Add(item3);
     Args.Add(item4);
     Args.Add(item5);
     Args.Add(item6);
     Args.Add(item7);
 }
Beispiel #17
0
        public ChromeTabPanel()
        {
            this.leftMargin           = 0.0;
            this.rightMargin          = 25.0;
            this.defaultMeasureHeight = 30.0;
            ComponentResourceKey key = new ComponentResourceKey(typeof(ChromeTabPanel), "addButtonStyle");
            Style addButtonStyle     = (Style)this.FindResource(key);

            this.addButton = new Button {
                Style = addButtonStyle
            };
            this.addButtonSize = new Size(20, 12);
        }
        private void AddFilterRulePanelItemContentTemplate(Type type, string resourceName)
        {
            Debug.Assert(type != null, "not null");
            Debug.Assert(!string.IsNullOrEmpty(resourceName), "not null");

            var templateInfo = new ComponentResourceKey(typeof(FilterRulePanel), resourceName);

            DataTemplate template = (DataTemplate)this.TryFindResource(templateInfo);

            Debug.Assert(template != null, "not null");

            this.AddFilterRulePanelItemContentTemplate(type, template);
        }
Beispiel #19
0
 static DataTemplates()
 {
     BooleanTrueFalseDataTemplateKey = new ComponentResourceKey(typeof(SharedResources), "BooleanTFDataTemplate");
     BooleanNameDataTemplateKey      = new ComponentResourceKey(typeof(SharedResources), "BooleanNameDataTemplate");
     ByteDataTemplateKey             = new ComponentResourceKey(typeof(SharedResources), "ByteDataTemplate");
     ByteFDataTemplateKey            = new ComponentResourceKey(typeof(SharedResources), "ByteFDataTemplate");
     ColorDataTemplateKey            = new ComponentResourceKey(typeof(SharedResources), "ColorDataTemplate");
     EnumDataTemplateKey             = new ComponentResourceKey(typeof(SharedResources), "EnumDataTemplate");
     Int16DataTemplateKey            = new ComponentResourceKey(typeof(SharedResources), "Int16DataTemplate");
     Int16FDataTemplateKey           = new ComponentResourceKey(typeof(SharedResources), "Int16FDataTemplate");
     Int32DataTemplateKey            = new ComponentResourceKey(typeof(SharedResources), "Int32DataTemplate");
     Int32FDataTemplateKey           = new ComponentResourceKey(typeof(SharedResources), "Int32FDataTemplate");
     StringDataTemplateKey           = new ComponentResourceKey(typeof(SharedResources), "StringDataTemplate");
 }
        /// <summary>
        ///     TypeConverter method implementation.
        /// </summary>
        /// <param name="context">
        ///     ITypeDescriptorContext
        /// </param>
        /// <param name="culture">
        ///     current culture (see CLR specs)
        /// </param>
        /// <param name="value">
        ///     value to convert from
        /// </param>
        /// <param name="destinationType">
        ///     Type to convert to
        /// </param>
        /// <returns>
        ///     converted value
        /// </returns>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            // Validate Input Arguments
            ComponentResourceKey key = value as ComponentResourceKey;

            if (key == null)
            {
                throw new ArgumentException(SR.Get(SRID.MustBeOfType, "value", "ComponentResourceKey"));
            }
            if (destinationType == null)
            {
                throw new ArgumentNullException("destinationType");
            }
            return(base.CanConvertTo(context, destinationType));
        }
        private static DataTemplate TryFindDataTemplate(FrameworkElement element, object dataTemplateKey)
        {
            if (dataTemplateKey.ToString().Contains("Task"))
            {
                // Todo: remove me after testing.
            }
            object dataTemplate = element.TryFindResource(dataTemplateKey);

            if (dataTemplate == null)
            {
                dataTemplateKey = new ComponentResourceKey(typeof(PropertyGrid), dataTemplateKey);
                dataTemplate    = element.TryFindResource(dataTemplateKey);
            }
            return(dataTemplate as DataTemplate);
        }
Beispiel #22
0
        static SharpTreeView()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(SharpTreeView),
                                                     new FrameworkPropertyMetadata(typeof(SharpTreeView)));

            SelectionModeProperty.OverrideMetadata(typeof(SharpTreeView),
                                                   new FrameworkPropertyMetadata(SelectionMode.Extended));

            AlternationCountProperty.OverrideMetadata(typeof(SharpTreeView),
                                                      new FrameworkPropertyMetadata(2));

            DefaultItemContainerStyleKey =
                new ComponentResourceKey(typeof(SharpTreeView), "DefaultItemContainerStyleKey");

            VirtualizingStackPanel.VirtualizationModeProperty.OverrideMetadata(typeof(SharpTreeView),
                                                                               new FrameworkPropertyMetadata(VirtualizationMode.Recycling));
        }
Beispiel #23
0
        public void ShouldReturnNothingForWrongComponentKey()
        {
            ComponentResourceKey key             = new ComponentResourceKey();
            ResourceLocatorMock  resourceLocator = new ResourceLocatorMock(key, null);

            GridEntryMock entry = new GridEntryMock {
                Editor = new EditorMock {
                    InlineTemplate = key
                }
            };
            GridEntryContainerMock container = new GridEntryContainerMock(resourceLocator)
            {
                Entry = entry
            };

            Assert.IsNull(container.EditorTemplate);
        }
        /// <summary>
        /// Re-define an existing <seealso cref="SolidColorBrush"/> and backup the originial color
        /// as it was before the application of the custom coloring.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="newColor"></param>
        private void ApplyToDynamicResource(ComponentResourceKey key, Color?newColor)
        {
            if (Application.Current.Resources[key] == null || newColor == null)
            {
                return;
            }

            // Re-coloring works with SolidColorBrushs linked as DynamicResource
            if (Application.Current.Resources[key] is SolidColorBrush)
            {
                //backupDynResources.Add(resourceName);

                var newColorBrush = new SolidColorBrush((Color)newColor);
                newColorBrush.Freeze();

                Application.Current.Resources[key] = newColorBrush;
            }
        }
        public ChromeTabPanel()
        {
            _leftMargin           = 0.0;
            _rightMargin          = 25.0;
            _defaultMeasureHeight = 30.0;

            var key            = new ComponentResourceKey(typeof(ChromeTabPanel), "AddButtonStyle");
            var addButtonStyle = (Style)FindResource(key);

            _addButton = new Button
            {
                Style = addButtonStyle
            };

            _addButtonSize = new Size(20, 12);

            Loaded   += OnLoaded;
            Unloaded += OnUnloaded;
        }
Beispiel #26
0
        public void ShouldReturnEditorWithComponentResourceKey()
        {
            ComponentResourceKey key      = new ComponentResourceKey();
            DataTemplate         template = new DataTemplate();

            ResourceLocatorMock resourceLocator = new ResourceLocatorMock(key, template);

            GridEntryMock entry = new GridEntryMock {
                Editor = new EditorMock {
                    InlineTemplate = key
                }
            };
            GridEntryContainerMock container = new GridEntryContainerMock(resourceLocator)
            {
                Entry = entry
            };

            Assert.AreEqual(template, container.EditorTemplate);
        }
 public I18nStringExtension(ComponentResourceKey key, object item0, object item1, object item2, object item3, object item4, object item5, object item6, object item7, object item8, object item9, object item10, object item11, object item12, object item13, object item14, object item15)
     : this(key)
 {
     Args.Add(item0);
     Args.Add(item1);
     Args.Add(item2);
     Args.Add(item3);
     Args.Add(item4);
     Args.Add(item5);
     Args.Add(item6);
     Args.Add(item7);
     Args.Add(item8);
     Args.Add(item9);
     Args.Add(item10);
     Args.Add(item11);
     Args.Add(item12);
     Args.Add(item13);
     Args.Add(item14);
     Args.Add(item15);
 }
Beispiel #28
0
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            // if the container has a Template defined, just return it.
            ContentPresenter cp = container as ContentPresenter;

            if (cp != null && cp.ContentTemplate != null)
            {
                return(cp.ContentTemplate);
            }

            // either return the built-in template for a string, or return null
            if (item is string)
            {
                ComponentResourceKey key = new ComponentResourceKey(typeof(TaskDialog), _templateName);
                DataTemplate         t   = Application.Current.TryFindResource(key) as DataTemplate;

                return(t);
            }
            return(null);
        }
Beispiel #29
0
        public ResourceHelper(ComponentResourceKey key, object owner = null, object defaultValue = null)
        {
            _key      = key;
            _defValue = defaultValue;
            switch (owner)
            {
            case FrameworkElement frameworkElement:
                frameworkElement.Loaded   += OnLoaded;
                frameworkElement.Unloaded += OnUnloaded;
                break;

            case FrameworkContentElement frameworkContentElement:
                frameworkContentElement.Loaded   += OnLoaded;
                frameworkContentElement.Unloaded += OnUnloaded;
                break;

            default:
                OnLoaded(null, null);
                break;
            }
        }
Beispiel #30
0
        public I18nSource(ComponentResourceKey key, object owner = null)
        {
            _key = key;

            switch (owner)
            {
            case FrameworkElement frameworkElement:
                frameworkElement.Loaded   += OnLoaded;
                frameworkElement.Unloaded += OnUnloaded;
                break;

            case FrameworkContentElement frameworkContentElement:
                frameworkContentElement.Loaded   += OnLoaded;
                frameworkContentElement.Unloaded += OnUnloaded;
                break;

            default:
                OnLoaded(null, null);
                break;
            }
        }