private static void OnMinimumChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RangeBar pan = (RangeBar)d;

            pan.CoerceValue(MaximumProperty);
            pan.OnMinimumChanged((double)e.OldValue, (double)e.NewValue);
        }
        private static object CoerceMaximum(DependencyObject d, object value)
        {
            RangeBar pan = (RangeBar)d;
            double   min = pan.Minimum;

            if ((double)value < min)
            {
                return(min);
            }
            return(value);
        }
        //When a new mod is selected, updates the info panel
        private void listViewMods_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (listViewMods.SelectedItem == null)
            {
                return;                                    //If a drag-drop operation is happening, returns;
            }
            string selectedModName = ((Mod)listViewMods.SelectedItem).Name;
            Mod    selectedMod     = modList[selectedModName];

            //Mod name
            labelModName.Content = selectedMod.Name;
            //Mod image
            BitmapImage bitmap = new BitmapImage();

            bitmap.BeginInit();
            bitmap.UriSource = new Uri(selectedMod.ImageUrl, UriKind.Absolute);
            bitmap.EndInit();
            imageModPicture.Source = bitmap;
            //Mod description
            labelDescription.Text = selectedMod.Description;
            //Mod file tree
            treeViewModFiles.Items.Clear();
            rangeBarTreeView.Children.Clear();
            if (selectedMod.PackFile != null)
            {
                BuildTree(selectedMod.PackFile.Root, treeViewModFiles.Items);
            }
            //Mod conflicts
            rangeBarMods.Children.Clear();
            if (selectedMod.Conflicts.Count > 0)
            {
                AddMarkOnRangeBar(rangeBarMods, listViewMods.SelectedIndex * 100 / listViewMods.Items.Count, new BrushConverter().ConvertFromString("#FF3761F1") as Brush);
            }
            foreach (Mod item in listViewMods.Items)
            {
                item.Overridden = item.Overrides = false;
                foreach (string modName in selectedMod.Conflicts.ConflictingMods())
                {
                    if (item.Name == modName)
                    {
                        int index = listViewMods.Items.IndexOf(item);
                        if (index > listViewMods.SelectedIndex)
                        {
                            item.Overridden = true;
                            AddMarkOnRangeBar(rangeBarMods, index * 100 / listViewMods.Items.Count, new BrushConverter().ConvertFromString("#FFFF7373") as Brush);
                        }
                        else
                        {
                            item.Overrides = true;
                            AddMarkOnRangeBar(rangeBarMods, index * 100 / listViewMods.Items.Count, new BrushConverter().ConvertFrom("#00e600") as Brush);
                        }
                    }
                }
            }

            //Internal method used to recursively populate the file tree
            void BuildTree(VirtualDirectory _virtualDirectory, ItemCollection _addInMe)
            {
                int _i = 0;

                RecursiveBuildTree(_virtualDirectory, _addInMe, ref _i);

                void RecursiveBuildTree(VirtualDirectory virtualDirectory, ItemCollection addInMe, ref int i) //i needs to be passed by reference so that every recoursive call increments the same counter
                {
                    TreeViewItem currentNode = new TreeViewItem();

                    currentNode.Header     = virtualDirectory.Name;
                    currentNode.IsExpanded = true;
                    i++;
                    foreach (var file in virtualDirectory.Files)
                    {
                        TreeViewItem childNode = new TreeViewItem();
                        childNode.Header = file.Name;
                        if (selectedMod.Conflicts.AnyConflict(file.FullPath))
                        {
                            childNode.ToolTip = $"Conflicts with:{Environment.NewLine}  {String.Join(Environment.NewLine + "  ", selectedMod.Conflicts.ConflictingMods(file.FullPath))}";
                            double position = i * 100 / selectedMod.PackFile.Root.AllEntries.Count;
                            if (selectedMod.Conflicts.ConflictingMods(file.FullPath).ToList().TrueForAll(otherMod => modList.IndexOf(modList[otherMod]) < modList.IndexOf(selectedMod)))
                            {
                                childNode.Foreground = Brushes.Green;
                                AddMarkOnRangeBar(rangeBarTreeView, position, new BrushConverter().ConvertFrom("#00e600") as Brush);
                            }
                            else
                            {
                                childNode.Foreground = Brushes.Red;
                                AddMarkOnRangeBar(rangeBarTreeView, position, new BrushConverter().ConvertFromString("#FFFF7373") as Brush);
                            }
                        }
                        currentNode.Items.Add(childNode);
                        i++;
                    }
                    foreach (var subdir in virtualDirectory.Subdirectories)
                    {
                        RecursiveBuildTree(subdir, currentNode.Items, ref i);
                    }
                    addInMe.Add(currentNode);
                }
            }

            //Internal method used to add marks on the scrollbar where the conflicting mods are
            void AddMarkOnRangeBar(RangeBar rangeBar, double position, Brush color)
            {
                System.Windows.Shapes.Rectangle r = new System.Windows.Shapes.Rectangle
                {
                    Fill                = color,
                    Height              = 4,
                    IsHitTestVisible    = false,
                    HorizontalAlignment = HorizontalAlignment.Stretch
                };
                RangeBar.SetPosition(r, position);
                rangeBar.Children.Add(r);
            }
        }