/// <summary> /// Calls <see cref="GuiTranslator" /> for the given object, if this functionality is not /// turned off in <see cref="GlobalSettings" /> and the given object is of type /// FrameworkElement or DataGridColumnHeader. /// </summary> private static void RunTranslator(object objectToBeTranslated) { if (!GlobalSettings.UseGuiTranslatorForLocalizationUtils) { return; } switch (objectToBeTranslated) { case DataGridColumnHeader asColumnHeader: try { GuiTranslator.TranslateGui( LogicalTreeUtils.GetDataGridParent(asColumnHeader.Column)); Logger.Log(LogLevel.Debug, "Translation of DataGridColumn successfully updated."); } catch { Logger.Log(LogLevel.Debug, "Unable to update new translation for DataGrid in GUI."); } break; case FrameworkElement asFrameworkElement: GuiTranslator.TranslateGui(asFrameworkElement); Logger.Log(LogLevel.Debug, "Translation of element successfully updated."); break; default: //no action, if GuiTranslator in unable to translate objectToBeTranslated. Logger.Log(LogLevel.Debug, "Translation of element was not successfully updated, " + "because it is not a Framework element."); break; } }
/// <summary> /// Attach Localizer to all supported GUI-elements /// </summary> /// <param name="parent"> /// The parent-element, whose GUI-elements should have the translation action attached/detached to/from them. /// </param> /// <param name="isActive">If true handlers will be attached, if not they will be removed.</param> /// <param name="calledByLoaded"> /// Whether this function was called by a "Loaded"-Event-Handler or not, determines whether the Event-Handler has /// to be removed from the event or not. /// </param> private static void ManageLocalizationEvents(DependencyObject parent, bool isActive, bool calledByLoaded) { Logger.Log(LogLevel.Debug, "Localizer will be {0} View (of type {1})", isActive ? "attached to" : "detached from", parent.DependencyObjectType.Name); //make sure views do not get initialized multiple times. if (calledByLoaded) { var parentFrameworkElement = (FrameworkElement)parent; parentFrameworkElement.Loaded -= ElementInitialized; Logger.Log(LogLevel.Debug, "Event handler was removed from Loaded-Event."); } else { Logger.Log(LogLevel.Debug, "Event handler was not removed from Loaded-Event."); } var supportedElements = new List <FrameworkElement>(); //read all supported child elements from parent supportedElements.AddRange(LogicalTreeUtils.GetLogicalChildCollection <RibbonTab>(parent)); supportedElements.AddRange(LogicalTreeUtils.GetLogicalChildCollection <RibbonGroup>(parent)); supportedElements.AddRange(LogicalTreeUtils.GetLogicalChildCollection <RibbonButton>(parent)); supportedElements.AddRange(LogicalTreeUtils.GetLogicalChildCollection <Label>(parent)); supportedElements.AddRange(LogicalTreeUtils.GetLogicalChildCollection <Button>(parent)); supportedElements.AddRange(LogicalTreeUtils.GetLogicalChildCollection <TabItem>(parent)); supportedElements.AddRange(LogicalTreeUtils.GetLogicalChildCollection <RadioButton>(parent)); supportedElements.AddRange(LogicalTreeUtils.GetLogicalChildCollection <TextBlock>(parent)); supportedElements.AddRange(LogicalTreeUtils.GetLogicalChildCollection <CheckBox>(parent)); //Since the LogicalTree doesn't include the DataGrids Headers, //this distinction will be made in OpenLocalizationDialog. supportedElements.AddRange(LogicalTreeUtils.GetLogicalChildCollection <DataGrid>(parent)); if (isActive) { foreach (var element in supportedElements) { element.MouseRightButtonUp += LocalizerDialogHandler.OpenLocalizationDialog; } Logger.Log(LogLevel.Debug, "Localizer was successfully attached to {0} elements.", supportedElements.Count); } else { foreach (var element in supportedElements) { element.MouseRightButtonUp -= LocalizerDialogHandler.OpenLocalizationDialog; } Logger.Log(LogLevel.Debug, "Localizer was successfully detached from {0} elements.", supportedElements.Count); } }