Esempio n. 1
0
        private void UpdateCar(TextBlockBindable child, ServerEntry.CarEntry car)
        {
            if (ReferenceEquals(car, child.DataContext) &&
                // Additional check, in case CarObjectWrapper changed
                ReferenceEquals(child.Bind?.Wrapper, car.CarObjectWrapper))
            {
                return;
            }

            InitializeBrushes();

            DisposeHelper.Dispose(ref child.Bind);
            if (_scrolling)
            {
                _carsTooltipsSet = false;
                child.ToolTip    = null;
            }

            var existingIcon = child.Inlines.FirstInline as InlineUIContainer;

            child.DataContext = car;
            var wrapper = car.CarObjectWrapper;

            if (wrapper != null)
            {
                child.Bind = new CarDisplayNameBind(child, wrapper);
            }
            else
            {
                child.Inlines.Clear();
                child.Inlines.AddRange(new [] {
                    existingIcon ?? GetErrorIconInline(),
                    new Run {
                        Text = car.Id
                    }
                }.NonNull());
                return;
            }

            if (existingIcon != null)
            {
                ReleaseErrorIconInline(existingIcon);
            }
        }
Esempio n. 2
0
        private void UpdateCars(ServerEntry n)
        {
            var array = n.Cars;

            var children  = _carsPanel.Children;
            var carsCount = Math.Min(array?.Count ?? 0, OptionCarsLimit);

            for (var i = children.Count - carsCount; i > 0; i--)
            {
                var last  = children.Count - 1;
                var child = (TextBlockBindable)children[last];
                DisposeHelper.Dispose(ref child.Bind);

                if (CarsPool.Count < CarsPoolSize)
                {
                    CarsPool.Add(child);
                }
                children.RemoveAt(last);
            }

            if (array == null)
            {
                return;
            }
            for (var i = 0; i < carsCount; i++)
            {
                TextBlockBindable child;
                if (i < children.Count)
                {
                    child = (TextBlockBindable)children[i];
                }
                else
                {
                    if (CarsPool.Count > 0)
                    {
                        var last = CarsPool.Count - 1;
                        child = CarsPool[last];
                        CarsPool.RemoveAt(last);
                    }
                    else
                    {
                        if (_smallStyle == null)
                        {
                            _smallStyle = (Style)FindResource(@"Small");
                        }

                        child = new TextBlockBindable {
                            Style      = _smallStyle,
                            Margin     = new Thickness(4, 0, 4, 0),
                            Padding    = new Thickness(2),
                            Height     = 20d,
                            Foreground = _blockText,
                            Background = _blockBackground
                        };
                    }

                    children.Add(child);
                }

                UpdateCar(child, array[i]);
            }
        }