예제 #1
0
        /// <summary>
        /// Получение локализованного (отображаемого) имени свойства с учётом двух атрибутов
        /// </summary>
        /// <param name="property">Свойство</param>
        private string GetPropertyDisplayName(IntellectualEntityProperty property)
        {
            try
            {
                var displayName =
                    ModPlusAPI.Language.GetItem(Invariables.LangItem, property.DisplayNameLocalizationKey);
                if (!string.IsNullOrEmpty(displayName))
                {
                    if (!string.IsNullOrEmpty(property.NameSymbolForStyleEditor))
                    {
                        // Обозначение свойства в редакторе стилей должно быть в скобочках и находиться в конце имени перед двоеточием
                        var symbol = property.NameSymbolForStyleEditor.TrimStart('(').TrimEnd(')');
                        displayName = $"{displayName.TrimEnd(':').Trim()} ({symbol}):";
                    }

                    return(displayName);
                }
            }
            catch
            {
                // ignore
            }

            return(string.Empty);
        }
예제 #2
0
        /// <summary>
        /// Создание двусторонней привязки для использования в элементе <see cref="NumericBox"/>
        /// По какой-то причине при привязке к типу object не работает. В связи с этим делаю такой вот
        /// лайфхак - добавляю в класс <see cref="IntellectualEntityProperty"/> два свойства конкретного типа.
        /// Это нужно, чтобы решить эту специфическую проблему в данном проекте и не менять из-за этого
        /// библиотеку оформления
        /// </summary>
        /// <param name="entityProperty">Свойство</param>
        /// <param name="isInteger">True - целое число. False - дробное число</param>
        private Binding CreateTwoWayBindingForPropertyForNumericValue(
            IntellectualEntityProperty entityProperty, bool isInteger)
        {
            var binding = new Binding
            {
                Mode = BindingMode.TwoWay,
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                Source = entityProperty,
                Path   = isInteger ? new PropertyPath("IntValue") : new PropertyPath("DoubleValue")
            };

            return(binding);
        }
예제 #3
0
        /// <summary>
        /// Создание двусторонней привязки к свойству
        /// </summary>
        /// <param name="entityProperty">Свойство</param>
        /// <param name="converter">Конвертер (при необходимости)</param>
        /// <returns>Объект типа <see cref="Binding"/></returns>
        private Binding CreateTwoWayBindingForProperty(IntellectualEntityProperty entityProperty, IValueConverter converter = null)
        {
            var binding = new Binding
            {
                Mode = BindingMode.TwoWay,
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                Source = entityProperty,
                Path   = new PropertyPath("Value")
            };

            if (converter != null)
            {
                binding.Converter = converter;
            }

            return(binding);
        }
예제 #4
0
        /// <summary>
        /// Получение локализованного описания свойства
        /// </summary>
        /// <param name="property">Свойство</param>
        private string GetPropertyDescription(IntellectualEntityProperty property)
        {
            try
            {
                var description = ModPlusAPI.Language.GetItem(Invariables.LangItem, property.DescriptionLocalizationKey);
                if (!string.IsNullOrEmpty(description))
                {
                    return(description);
                }
            }
            catch
            {
                // ignore
            }

            return(string.Empty);
        }