Exemplo n.º 1
0
        /// <summary>
        /// The on value changed.
        /// </summary>
        /// <param name="dependencyObject"> The dependency object. </param>
        /// <param name="e"> The Event Arguments. </param>
        private static void OnValueChanged(
            DependencyObject dependencyObject,
            DependencyPropertyChangedEventArgs e)
        {
            ElasticListBoxItem listBoxItem = (ElasticListBoxItem)dependencyObject;
            ElasticListBox     listBox     = listBoxItem.ParentListBox;

            // Update the total.
            var items = listBox.Items
                        .Cast <object>()
                        .Select(x => listBoxItem.ParentListBox.ItemContainerGenerator.ContainerFromItem(x))
                        .Where(x => x != null)
                        .Cast <ElasticListBoxItem>();

            listBox.Total = items.Sum(x => x.Value);

            // Update the percentage.
            foreach (var item in items)
            {
                if (listBox.Total == 0D)
                {
                    item.Percentage        = 0D;
                    item.PercentageOpacity = listBoxItem.MinOpacity;
                }
                else
                {
                    item.Percentage        = item.Value / listBox.Total;
                    item.PercentageOpacity = Math.Max(listBoxItem.MinOpacity, item.Percentage);
                }
            }

            listBox.ResizeItems();
        }
Exemplo n.º 2
0
        /// <summary>
        /// The on is highlighted changed.
        /// </summary>
        /// <param name="dependencyObject"> The dependency object. </param>
        /// <param name="e"> The Event Arguments. </param>
        private static void OnIsHighlightedChanged(
            DependencyObject dependencyObject,
            DependencyPropertyChangedEventArgs e)
        {
            ElasticListBoxItem listBoxItem = (ElasticListBoxItem)dependencyObject;
            ElasticListBox     listBox     = listBoxItem.ParentListBox;

            listBox.ResizeItems();
        }