public static void CreateNewLanguageColumn(this DataGrid dataGrid, Configuration configuration, CultureInfo?culture)
        {
            var cultureKey = new CultureKey(culture);

            dataGrid.AddLanguageColumn(configuration, cultureKey);

            var key = cultureKey.ToString(NeutralCultureKeyString);

            HiddenLanguageColumns = HiddenLanguageColumns.Where(col => !string.Equals(col, key, StringComparison.OrdinalIgnoreCase));
        }
        public static void CreateNewLanguageColumn([NotNull] this DataGrid dataGrid, [NotNull] Configuration configuration, [CanBeNull] CultureInfo culture)
        {
            Contract.Requires(dataGrid != null);
            Contract.Requires(configuration != null);

            var cultureKey = new CultureKey(culture);

            dataGrid.AddLanguageColumn(configuration, cultureKey);

            var key = cultureKey.ToString(NeutralCultureKeyString);

            HiddenLanguageColumns = HiddenLanguageColumns.Where(col => !string.Equals(col, key, StringComparison.OrdinalIgnoreCase));
        }
        public static void CreateNewLanguageColumn(this DataGrid dataGrid, ResourceManager resourceManager, CultureInfo culture)
        {
            Contract.Requires(dataGrid != null);
            Contract.Requires(resourceManager != null);

            var cultureKey = new CultureKey(culture);

            AddLanguageColumn(dataGrid, resourceManager, cultureKey);

            var key = cultureKey.ToString(NeutralCultureKeyString);

            HiddenLanguageColumns = HiddenLanguageColumns.Where(col => !string.Equals(col, key, StringComparison.OrdinalIgnoreCase));
        }
        private static void AddLanguageColumn(this DataGrid dataGrid, Configuration configuration, CultureKey cultureKey)
        {
            var columns = dataGrid.Columns;
            var key     = cultureKey.ToString(NeutralCultureKeyString);

            var culture         = cultureKey.Culture;
            var languageBinding = culture != null
                ? new Binding {
                Source = culture
            }
                : new Binding("NeutralResourcesLanguage")
            {
                Source = configuration
            };

            languageBinding.Converter = CultureToXmlLanguageConverter.Default;
            // It's important to explicitly set the converter culture here, else we will get a binding error, because here the source for the converter culture is the target of the binding.
            languageBinding.ConverterCulture = CultureInfo.InvariantCulture;

            var flowDirectionBinding = culture != null
                ? new Binding("TextInfo.IsRightToLeft")
            {
                Source = culture
            }
                : new Binding("NeutralResourcesLanguage.TextInfo.IsRightToLeft")
            {
                Source = configuration
            };

            flowDirectionBinding.Converter = IsRightToLeftToFlowDirectionConverter.Default;

            var cellStyle = new Style(typeof(DataGridCell), dataGrid.CellStyle);

            cellStyle.Setters.Add(new Setter(ResourceFileExistsProperty, new Binding(@"FileExists[" + key + @"]")));

            var commentCellStyle = new Style(typeof(DataGridCell), cellStyle);

            commentCellStyle.Setters.Add(new Setter(CellAnnotationsProperty, new Binding(@"CommentAnnotations[" + key + @"]")));

            var commentColumn = new DataGridTextColumn
            {
                Header     = new CommentHeader(configuration, cultureKey),
                Binding    = new Binding(@"Comments[" + key + @"]"),
                MinWidth   = 50,
                CellStyle  = commentCellStyle,
                Width      = new DataGridLength(1, DataGridLengthUnitType.Star),
                Visibility = VisibleCommentColumns.Contains(key, StringComparer.OrdinalIgnoreCase) ? Visibility.Visible : Visibility.Hidden
            };

            columns.AddLanguageColumn(commentColumn, languageBinding, flowDirectionBinding);

            var textCellStyle = new Style(typeof(DataGridCell), cellStyle)
            {
                Setters =
                {
                    new Setter(CellAnnotationsProperty, new Binding(@"ValueAnnotations[" + key + @"]")),
                    new Setter(IsCellInvariantProperty, new Binding(@"IsItemInvariant[" + key + @"]")),
                }
            };

            var textElementStyle = new Style(typeof(TextBlock))
            {
                Triggers =
                {
                    new DataTrigger
                    {
                        Binding = new Binding(nameof(Settings.IsWrapLinesEnabled))
                        {
                            Source = Settings.Default
                        },
                        Value   = true,
                        Setters ={ new Setter(TextBlock.TextWrappingProperty,           TextWrapping.WrapWithOverflow) }
                    }
                }
            };

            var column = new DataGridTextColumn
            {
                Header       = new LanguageHeader(configuration, cultureKey),
                Binding      = new Binding(@"Values[" + key + @"]"),
                MinWidth     = 120,
                CellStyle    = textCellStyle,
                ElementStyle = textElementStyle,
                Width        = new DataGridLength(2, DataGridLengthUnitType.Star),
                Visibility   = HiddenLanguageColumns.Contains(key, StringComparer.OrdinalIgnoreCase) ? Visibility.Hidden : Visibility.Visible
            };

            columns.AddLanguageColumn(column, languageBinding, flowDirectionBinding);
        }
        private static void AddLanguageColumn([NotNull] this DataGrid dataGrid, [NotNull] Configuration configuration, [NotNull] CultureKey cultureKey)
        {
            Contract.Requires(dataGrid != null);
            Contract.Requires(configuration != null);
            Contract.Requires(cultureKey != null);

            var columns = dataGrid.Columns;

            var key = cultureKey.ToString(NeutralCultureKeyString);

            var culture         = cultureKey.Culture;
            var languageBinding = culture != null
                ? new Binding {
                Source = culture
            }
                : new Binding("NeutralResourcesLanguage")
            {
                Source = configuration
            };

            languageBinding.Converter = CultureToXmlLanguageConverter.Default;
            // It's important to explicitly set the converter culture here, else we will get a binding error, because here the source for the converter culture is the target of the binding.
            languageBinding.ConverterCulture = CultureInfo.InvariantCulture;

            var flowDirectionBinding = culture != null
                ? new Binding("TextInfo.IsRightToLeft")
            {
                Source = culture
            }
                : new Binding("NeutralResourcesLanguage.TextInfo.IsRightToLeft")
            {
                Source = configuration
            };

            flowDirectionBinding.Converter = IsRightToLeftToFlowDirectionConverter.Default;

            var cellStyle = new Style(typeof(DataGridCell), dataGrid.CellStyle);

            cellStyle.Setters.Add(new Setter(ResourceFileExistsProperty, new Binding(@"FileExists[" + key + @"]")));

            var commentCellStyle = new Style(typeof(DataGridCell), cellStyle);

            commentCellStyle.Setters.Add(new Setter(CellAnnotationsProperty, new Binding(@"CommentAnnotations[" + key + @"]")));

            var commentColumn = new DataGridTextColumn
            {
                Header     = new CommentHeader(configuration, cultureKey),
                Binding    = new Binding(@"Comments[" + key + @"]"),
                MinWidth   = 50,
                CellStyle  = commentCellStyle,
                Width      = new DataGridLength(1, DataGridLengthUnitType.Star),
                Visibility = VisibleCommentColumns.Contains(key, StringComparer.OrdinalIgnoreCase) ? Visibility.Visible : Visibility.Hidden
            };

            columns.AddLanguageColumn(commentColumn, languageBinding, flowDirectionBinding);

            var textCellStyle = new Style(typeof(DataGridCell), cellStyle);

            textCellStyle.Setters.Add(new Setter(CellAnnotationsProperty, new Binding(@"ValueAnnotations[" + key + @"]")));

            var column = new DataGridTextColumn
            {
                Header     = new LanguageHeader(configuration, cultureKey),
                Binding    = new Binding(@"Values[" + key + @"]"),
                MinWidth   = 120,
                CellStyle  = textCellStyle,
                Width      = new DataGridLength(2, DataGridLengthUnitType.Star),
                Visibility = HiddenLanguageColumns.Contains(key, StringComparer.OrdinalIgnoreCase) ? Visibility.Hidden : Visibility.Visible
            };

            columns.AddLanguageColumn(column, languageBinding, flowDirectionBinding);
        }