public override bool Equals(object obj) { ComponentResourceKey other = obj as ComponentResourceKey; return(Object.ReferenceEquals(this, other) || !Object.ReferenceEquals(other, null) && Object.Equals(this.TypeInTargetAssembly, other.TypeInTargetAssembly) && Object.Equals(this.ResourceId, other.ResourceId)); }
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); }
private static ComponentResourceKey Get([CallerMemberName] string caller = null) { ComponentResourceKey key; if (!_keys.TryGetValue(caller, out key)) { key = new ComponentResourceKey(typeof(Keys),caller); _keys.Add(caller, key); } return key; }
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; }
/// <summary> /// Determines if the passed in object is equal to this object. /// Two keys will be equal if they both have equal Types and IDs. /// </summary> /// <param name="o">The object to compare with.</param> /// <returns>True if the objects are equal. False otherwise.</returns> public override bool Equals(object o) { ComponentResourceKey key = o as ComponentResourceKey; if (key != null) { return(((key._typeInTargetAssembly != null) ? key._typeInTargetAssembly.Equals(this._typeInTargetAssembly) : (this._typeInTargetAssembly == null)) && ((key._resourceId != null) ? key._resourceId.Equals(this._resourceId) : (this._resourceId == null))); } return(false); }
public ChromeTabPanel() { this.maxTabWidth = 125.0; this.minTabWidth = 40.0; this.leftMargin = 0.0; this.rightMargin = 25.0; this.overlap = 10.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 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; }
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)); }
/// <summary>Determines whether the provided object is equal to the current <see cref="T:System.Windows.ComponentResourceKey" />. </summary> /// <param name="o">Object to compare with the current <see cref="T:System.Windows.ComponentResourceKey" />.</param> /// <returns> /// <see langword="true" /> if the objects are equal; otherwise, <see langword="false" />.</returns> // Token: 0x06000348 RID: 840 RVA: 0x0000945C File Offset: 0x0000765C public override bool Equals(object o) { ComponentResourceKey componentResourceKey = o as ComponentResourceKey; if (componentResourceKey == null) { return(false); } if (!((componentResourceKey._typeInTargetAssembly != null) ? componentResourceKey._typeInTargetAssembly.Equals(this._typeInTargetAssembly) : (this._typeInTargetAssembly == null))) { return(false); } if (componentResourceKey._resourceId == null) { return(this._resourceId == null); } return(componentResourceKey._resourceId.Equals(this._resourceId)); }
public ChromeTabPanel() { _maxTabWidth = 125.0; _minTabWidth = 40.0; _leftMargin = 50.0; _rightMargin = 30.0; _overlap = 10.0; _defaultMeasureHeight = 30.0; var key = new ComponentResourceKey(typeof (ChromeTabPanel), "addButtonStyle"); var addButtonStyle = (Style) FindResource(key); //_addButton = new Button { Style = addButtonStyle }; _addButton = new Button(); _addButton.Width = 0; _addButton.Height = 0; _addButtonSize = new Size(20, 12); _hoverBrush = (Brush) FindResource("HoverSelectionBrush"); _pressedBrush = (Brush) FindResource("PressedSelectionBrush"); }
static SharpGridView() { ItemContainerStyleKey = new ComponentResourceKey(typeof(SharpTreeView), "GridViewItemContainerStyleKey"); }
/// <summary> Add the Editor for this PropertyType if not already added </summary> protected virtual void AddEditor(Type type, ComponentResourceKey editor) { var found = Editor.Editors.FindTypeEditor(type); if (found != null) return; Editor.Editors.Add(new TypeEditor(type, editor)); }
private void UpdateProperties() { if (_propertySource == null) _propertySource = new PropertySource(); _propertySource.Name = (IsUntitled) ? UntitledName : Path.GetFileName(Uri.LocalPath); _propertySource.TypeName = "Texture"; var textBlockKey = new ComponentResourceKey(typeof(PropertyGrid), "TextBlock"); _propertySource.Properties.Clear(); _propertySource.Properties.Add(new CustomProperty { Category = "Misc", Name = "File name", Value = this.GetName(), Description = "The filename of the image.", PropertyType = typeof(string), //DataTemplateKey = textBlockKey, CanReset = false, IsReadOnly = true, }); _propertySource.Properties.Add(new CustomProperty { Category = "Misc", Name = "Size", Value = Texture2D?.Width, Description = "Image width in pixels.", PropertyType = typeof(int), DataTemplateKey = textBlockKey, CanReset = false, IsReadOnly = true, }); _propertySource.Properties.Add(new CustomProperty { Category = "Misc", Name = "Height", Value = Texture2D?.Height, Description = "Image height in pixels.", PropertyType = typeof(int), DataTemplateKey = textBlockKey, CanReset = false, IsReadOnly = true, }); _propertySource.Properties.Add(new CustomProperty { Category = "Misc", Name = "Format", Value = Texture2D?.Format, Description = null, PropertyType = typeof(SurfaceFormat), DataTemplateKey = textBlockKey, CanReset = false, IsReadOnly = true, }); _propertySource.Properties.Add(new CustomProperty { Category = "Misc", Name = "Mipmap levels", Value = Texture2D?.LevelCount, Description = null, PropertyType = typeof(int), DataTemplateKey = textBlockKey, CanReset = false, IsReadOnly = true, }); }
object GetResource(string resourceName) { ComponentResourceKey key = new ComponentResourceKey(typeof(RapidFindReplaceControl), resourceName); return TryFindResource(key); }
private static object Template_CoerceValue(DependencyObject sender, object baseValue) { if (baseValue != null) return baseValue; var control = sender as DataGridFilterColumnControl; // Just resolved the binding to the template property attached to the column, and the value has not been set on the column: // => try to find the default template based on the columns type. var columnType = control?.ColumnHeader?.Column?.GetType(); if (columnType == null) return null; var resourceKey = new ComponentResourceKey(typeof(DataGridFilter), columnType); return control.DataGrid.GetResourceLocator()?.FindResource(control, resourceKey) ?? control.TryFindResource(resourceKey); }
/// <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); }
private void UpdateProperties() { // TODO: We could skip this if the Properties window is hidden. // Avoid redundant execution if several updates are queued. if (!_updateProperties) return; _updateProperties = false; _propertySource.Name = IsUntitled ? UntitledName : Path.GetFileName(Uri.LocalPath); _propertySource.TypeName = (DocumentType.Name != TextDocumentFactory.AnyDocumentTypeName) ? DocumentType.Name : "Text file"; var textBlockKey = new ComponentResourceKey(typeof(PropertyGrid), "TextBlock"); _propertySource.Properties.Clear(); _propertySource.Properties.Add(new CustomProperty { Category = "File", Name = "File name", Value = this.GetName(), Description = "The filename of the image.", PropertyType = typeof(string), //DataTemplateKey = textBlockKey, CanReset = false, IsReadOnly = true, }); _propertySource.Properties.Add(new CustomProperty { Category = "Text", Name = "Character count", Value = AvalonEditDocument.TextLength, Description = "The number of characters including whitespace characters.", PropertyType = typeof(int), DataTemplateKey = textBlockKey, CanReset = false, IsReadOnly = true, }); int numberOfWords; LineEndingType lineEndingType; GetTextStatistics(AvalonEditDocument.Text, out numberOfWords, out lineEndingType); _propertySource.Properties.Add(new CustomProperty { Category = "Text", Name = "Word count", Value = numberOfWords, Description = "The number of words.", PropertyType = typeof(int), DataTemplateKey = textBlockKey, CanReset = false, IsReadOnly = true, }); _propertySource.Properties.Add(new CustomProperty { Category = "Text", Name = "Line endings", Value = GetLineEndingName(lineEndingType), Description = "The line endings used in the text.", PropertyType = typeof(string), DataTemplateKey = textBlockKey, CanReset = false, IsReadOnly = true, }); if (_encoding != null) { _propertySource.Properties.Add(new CustomProperty { Category = "Text", Name = "Encoding", Value = _encoding.EncodingName, Description = "The encoding used in the file.", PropertyType = typeof(string), DataTemplateKey = textBlockKey, CanReset = false, IsReadOnly = true, }); } if (_fileInfo != null) { _propertySource.Properties.Add(new CustomProperty { Category = "File", Name = "File size", Value = string.Format(CultureInfo.CurrentCulture, "{0:F2} kB", _fileInfo.Length / 1024.0), Description = "The file size in kilobyte (1kB = 1024 bytes).", PropertyType = typeof(string), DataTemplateKey = textBlockKey, CanReset = false, IsReadOnly = true, }); _propertySource.Properties.Add(new CustomProperty { Category = "File", Name = "Last modified", Value = string.Format(CultureInfo.CurrentCulture, "{0}", _fileInfo.LastWriteTime), Description = "The time of the last write access.", PropertyType = typeof(string), DataTemplateKey = textBlockKey, CanReset = false, IsReadOnly = true, }); } }
/// <summary> /// Registers any attributed resource keys found on the type</summary> /// <param name="type">Type, usually a static set of keys</param> /// <param name="resourcePath">Path to resources</param> public static void Register(Type type, string resourcePath) { if (s_registeredTypes.Contains(type)) return; s_registeredTypes.Add(type); // Generate packUri AssemblyName assmName = type.Assembly.GetName(); string relativePackUriBase = "/" + assmName.Name + ";component/" + resourcePath; string absolutePackUriBase = "pack://application:,,," + relativePackUriBase; var imageResources = new ResourceDictionary(); FieldInfo[] fields = type.GetFields(BindingFlags.Static | BindingFlags.Public); foreach (FieldInfo field in fields) { // Get Image attributes object[] attributes = field.GetCustomAttributes(typeof(WpfImageResourceAttribute), false); if (attributes.Length > 0) { if(!field.FieldType.IsAssignableFrom(typeof(ResourceKey))) { System.Diagnostics.Debug.WriteLine("Warning: WpfImageResourceAttribute used on a field which is not a ResourceKey"); } var attribute = (WpfImageResourceAttribute)attributes[0]; Freezable img = null; string extension = System.IO.Path.GetExtension(attribute.ImageName).ToLower(); if (extension == ".bmp" || extension == ".png" || extension == ".ico") { var uri = new Uri(absolutePackUriBase + attribute.ImageName); img = new BitmapImage(uri); } else if (extension == ".xaml") { var uri = new Uri(relativePackUriBase + attribute.ImageName, UriKind.Relative); img = Application.LoadComponent(uri) as Freezable; if (img == null) { throw new InvalidOperationException("Invalid xaml image resource: " + attribute.ImageName); } } else { throw new InvalidOperationException("Unrecognized Wpf image resource file extension for file: " + attribute.ImageName); } if (img != null) { if (img.CanFreeze && !img.IsFrozen) img.Freeze(); object imageKey = type.FullName + "." + attribute.ImageName; if (field.FieldType.IsAssignableFrom(typeof(ResourceKey))) { imageKey = new ComponentResourceKey(type, imageKey); } field.SetValue(type, imageKey); imageResources.Add(imageKey, img); } } // Get ResourceDictionary attributes if(field.FieldType == typeof(string)) { attributes = field.GetCustomAttributes(typeof(ResourceDictionaryResourceAttribute), false); if (attributes.Length > 0) { var attribute = attributes[0] as ResourceDictionaryResourceAttribute; var dictionary = new ResourceDictionary(); string uri = absolutePackUriBase + attribute.Path; dictionary.Source = new Uri(uri, UriKind.RelativeOrAbsolute); Application.Current.Resources.MergedDictionaries.Add(dictionary); } } } Application.Current.Resources.MergedDictionaries.Add(imageResources); }
private void AddFilterRulePanelItemContentTemplate(Type type, string resourceName) { Debug.Assert(null != type); Debug.Assert(!String.IsNullOrEmpty(resourceName)); var templateInfo = new ComponentResourceKey(typeof(FilterRulePanel), resourceName); DataTemplate template = (DataTemplate)this.TryFindResource(templateInfo); Debug.Assert(null != template); this.AddFilterRulePanelItemContentTemplate(type, template); }
/// <summary> /// The try to find data template. /// </summary> /// <param name="element"> /// The element. /// </param> /// <param name="type"> /// The type. /// </param> /// <returns> /// </returns> 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; }
static ResourceKeys() { SomeBrush = new ComponentResourceKey(); }