Ejemplo n.º 1
0
        /// <summary>
        /// Add bindable property value
        /// </summary>
        /// <param name="inlines">Inlines to fill</param>
        /// <param name="tipProperty">Property</param>
        /// <param name="source">Source object</param>
        private static void _AddBindableProperty(InlineCollection inlines, TipProperty tipProperty, object source)
        {
            try
            {
                PropertyPath propertyPath = new PropertyPath(tipProperty.PrefixPath + tipProperty.Name);

                Binding binding = new Binding();
                binding.Path   = propertyPath;
                binding.Source = source;

                FrameworkElement fe = new FrameworkElement();
                BindingOperations.SetBinding(fe, FrameworkElement.DataContextProperty, binding);

                object value = fe.DataContext;
                if (value != null)
                {
                    string valueStr;

                    if (value is double && tipProperty.ValueUnits.HasValue && tipProperty.DisplayUnits.HasValue)
                    {
                        Unit valueUnits   = tipProperty.ValueUnits.Value;
                        Unit displayUnits = tipProperty.DisplayUnits.Value;
                        if (valueUnits != displayUnits)
                        {
                            value = UnitConvertor.Convert((double)value, valueUnits, displayUnits);
                        }

                        valueStr = UnitFormatter.Format((double)value, displayUnits);
                    }
                    else
                    {
                        // Special case for planned date
                        if (tipProperty.Name.Equals(Order.PropertyNamePlannedDate))
                        {
                            DateTime dateTime = (DateTime)value;
                            valueStr = dateTime.ToShortDateString();
                        }
                        else if (tipProperty.Name.Equals(Stop.PropertyNameStopType))
                        {
                            valueStr = _GetStopTypeStr((StopType)value, (Stop)source);
                        }
                        else
                        {
                            valueStr = value.ToString();
                        }
                    }

                    if (valueStr.Length > 0)
                    {
                        _AddLine(tipProperty.Title, valueStr, inlines, false);
                    }
                }

                BindingOperations.ClearBinding(fe, FrameworkElement.DataContextProperty);
            }
            catch (Exception ex)
            {
                Logger.Info(ex);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add property tip to list
        /// </summary>
        private void _AddPropertyTip(string prePath, string name, string title, IList<object> mapProperties,
            IList<object> selectedMapProperties, StringCollection selectedConfig, Unit? valueUnits, Unit? displayUnits)
        {
            if (name.Equals(Order.PropertyNameName, StringComparison.OrdinalIgnoreCase) ||
                name.Equals(ARRIVETIME_PROP_NAME, StringComparison.OrdinalIgnoreCase) ||
                name.Equals(Order.PropertyNameTimeWindow, StringComparison.OrdinalIgnoreCase) ||
                name.Equals(Order.PropertyNameTimeWindow2, StringComparison.OrdinalIgnoreCase))
            {
                if (!_notSelectableProperties.Keys.Contains(name))
                    _notSelectableProperties.Add(name, title);

                return;
            }

            foreach (TipProperty property in mapProperties)
            {
                if (title.Equals(property.ToString(), StringComparison.OrdinalIgnoreCase))
                    return;
            }

            if (title.Length != 0)
            {
                TipProperty tipProperty = new TipProperty(name, title, valueUnits, displayUnits);
                tipProperty.PrefixPath = prePath;
                mapProperties.Add(tipProperty);
                if (selectedConfig.Contains(name))
                {
                    selectedMapProperties.Add(tipProperty);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add bindable property value
        /// </summary>
        /// <param name="inlines">Inlines to fill</param>
        /// <param name="tipProperty">Property</param>
        /// <param name="source">Source object</param>
        private static void _AddBindableProperty(InlineCollection inlines, TipProperty tipProperty, object source)
        {
            try
            {
                PropertyPath propertyPath = new PropertyPath(tipProperty.PrefixPath + tipProperty.Name);

                Binding binding = new Binding();
                binding.Path = propertyPath;
                binding.Source = source;

                FrameworkElement fe = new FrameworkElement();
                BindingOperations.SetBinding(fe, FrameworkElement.DataContextProperty, binding);

                object value = fe.DataContext;
                if (value != null)
                {
                    string valueStr;

                    if (value is double && tipProperty.ValueUnits.HasValue && tipProperty.DisplayUnits.HasValue)
                    {
                        Unit valueUnits = tipProperty.ValueUnits.Value;
                        Unit displayUnits = tipProperty.DisplayUnits.Value;
                        if (valueUnits != displayUnits)
                            value = UnitConvertor.Convert((double)value, valueUnits, displayUnits);

                        valueStr = UnitFormatter.Format((double)value, displayUnits);
                    }
                    else
                    {
                        // Special case for planned date
                        if (tipProperty.Name.Equals(Order.PropertyNamePlannedDate))
                        {
                            DateTime dateTime = (DateTime) value;
                            valueStr = dateTime.ToShortDateString();
                        }
                        else if (tipProperty.Name.Equals(Stop.PropertyNameStopType))
                        {
                            valueStr = _GetStopTypeStr((StopType)value, (Stop)source);
                        }
                        else
                        {
                            valueStr = value.ToString();
                        }
                    }

                    if (valueStr.Length > 0)
                    {
                        _AddLine(tipProperty.Title, valueStr, inlines, false);
                    }
                }

                BindingOperations.ClearBinding(fe, FrameworkElement.DataContextProperty);
            }
            catch (Exception ex)
            {
                Logger.Info(ex);
            }
        }