/// <summary>
        /// // Show the stat of the item selected in the user control
        /// </summary>
        /// <param name="item">The item we want to show</param>
        private void LoadItemsStatsToContent(EnchantedItem item, bool itemCanBeRemoved = false)
        {
            UcStatsItems uc = new UcStatsItems();

            LoadItemToUserControlStats(item, uc, itemCanBeRemoved);
            CCtrlItemStats.Content = uc;
        }
 /// <summary>
 /// Create a modal form for the selected item when we do a right click
 /// </summary>
 private void ItemsDataGrid_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
 {
     if (ItemsDataGrid.SelectedItem != null)
     {
         // Create a modal form who contains the stats of the item selected
         EnchantedItem item = new EnchantedItem((Item)ItemsDataGrid.SelectedItem);
         CreateModalOfItemStats(item);
     }
 }
 /// <summary>
 /// Show the detailed stats of the item selected
 /// </summary>
 private void ItemsDataGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
 {
     if (ItemsDataGrid.SelectedItem != null)
     {
         EnchantedItem item = new EnchantedItem((Item)ItemsDataGrid.SelectedItem);
         // Show the stat of the item selected in the user control
         LoadItemsStatsToContent(item);
     }
 }
        /// <summary>
        /// // Create a modal form who contains the stats of the item selected
        /// </summary>
        /// <param name="item">The item we want to show</param>
        /// <param name="itemCanBeEquiped">If true, then the button for equiped the item will be showed. Else it will be the button for removing the item that will be showed</param>
        private void CreateModalOfItemStats(EnchantedItem item)
        {
            ModalItemStats modal = new ModalItemStats();
            UcStatsItems   uc    = new UcStatsItems();

            LoadItemToUserControlStats(item, uc);
            modal.CCtrlItemStats.Content = uc;
            modal.Show();
            // We have to bring the modal form in front after displaying it
            modal.Topmost = true;
        }
        /// <summary>
        /// Event that is triggered when we click on an image of the equipement
        /// </summary>
        private void Image_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Image         img  = (Image)sender;
            EnchantedItem item = new EnchantedItem();

            if (img.Tag != null)
            {
                item = ActualBuild.GetEquipedItemById((int)img.Tag);

                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    // Left click, we load the item stats to the user control of stats
                    LoadItemsStatsToContent(item, true);
                }
                else if (e.RightButton == MouseButtonState.Pressed)
                {
                    // Right click, we load the item stats to a new modal of stats
                    CreateModalOfItemStats(item);
                }
            }
        }
        /// <summary>
        /// Event triggered when a checkbox of elements is clicked
        /// </summary>
        private void CbxItemElement_Click(object sender, RoutedEventArgs e)
        {
            // The checkbox tag contains his parent stackpanel
            // That stackpanel contains the others checkbox of elements and the item corresponding
            CheckBox      cbx  = (CheckBox)sender;
            StackPanel    sp   = (StackPanel)cbx.Tag;
            EnchantedItem item = (EnchantedItem)sp.Tag;

            // Count and verify the elements selected
            bool masteries = true;
            bool fire      = false;
            bool water     = false;
            bool earth     = false;
            bool air       = false;
            int  count     = 0;

            foreach (CheckBox c in sp.Children)
            {
                if (c.IsChecked == true)
                {
                    count++;
                    switch (c.Name)
                    {
                    case GlobalConstants.FIRE_STRING:
                        fire = true;
                        break;

                    case GlobalConstants.WATER_STRING:
                        water = true;
                        break;

                    case GlobalConstants.EARTH_STRING:
                        earth = true;
                        break;

                    case GlobalConstants.AIR_STRING:
                        air = true;
                        break;

                    default:
                        Console.WriteLine("Unknown name for checkbox of element");
                        break;
                    }
                }
            }
            // Uncheck the checkbox if too many elements have been selected
            if (sp.Name == GlobalConstants.MASTERIES_STRING)
            {
                masteries = true;
                if (count > item.MasteriesElementsRequired)
                {
                    cbx.IsChecked = false;
                    return;
                }
            }
            else if (sp.Name == GlobalConstants.RESISTANCES_STRING)
            {
                masteries = false;
                if (count > item.ResistancesElementsRequired)
                {
                    cbx.IsChecked = false;
                    return;
                }
            }
            else
            {
                Console.WriteLine("Unknown name for the stackpanel");
                return; // We don't want to transmute the items if the name is unknown
            }
            // Finally transmute the elements of the item, even if the total of elements selected is insufficient
            item.TransmutateItemElements(masteries, fire, water, earth, air);
        }
        /// <summary>
        /// Create a CheckBox corresponding to an element for a specifical StackPanel
        /// </summary>
        /// <param name="imageSourcePath">Path that correspond to an element</param>
        /// <param name="sp">The StackPanel parent of the CheckBox</param>
        /// <returns></returns>
        private CheckBox CreateCheckboxElement(string imageSourcePath, StackPanel sp, int idStat)
        {
            ImageSourceConverter converter = new ImageSourceConverter();
            CheckBox             cbx       = new CheckBox();
            // Recover the item stocked in the StackPanel tag
            EnchantedItem item = (EnchantedItem)sp.Tag;

            // Create the image for the checkbox
            Image img = new Image();

            img.Source  = (ImageSource)converter.ConvertFromString(imageSourcePath);
            cbx.Content = img;

            // Create the event click for the checkbox and save the differents informations that needed
            // Saving the stackpanel to the tag of the checkbox allows to save the two objects in one properties
            cbx.Tag    = sp;
            cbx.Name   = GlobalConstants.GetElemStringFromImagePath(imageSourcePath);
            cbx.Click += CbxItemElement_Click;

            // Check automatically the checkbox if atleast one element is already selected
            if (item.FireMastery != 0 || item.WaterMastery != 0 || item.EarthMastery != 0 || item.AirMastery != 0 ||
                item.FireResistance != 0 || item.WaterResistance != 0 || item.EarthResistance != 0 || item.AirResistance != 0)
            {
                switch (imageSourcePath)
                {
                case GlobalConstants.FIRE_IMAGE_PATH:
                    if (sp.Name == GlobalConstants.MASTERIES_STRING && item.FireMastery > 0)
                    {
                        cbx.IsChecked = true;
                    }
                    if (sp.Name == GlobalConstants.RESISTANCES_STRING && item.FireResistance > 0)
                    {
                        cbx.IsChecked = true;
                    }
                    break;

                case GlobalConstants.WATER_IMAGE_PATH:
                    if (sp.Name == GlobalConstants.MASTERIES_STRING && item.WaterMastery > 0)
                    {
                        cbx.IsChecked = true;
                    }
                    if (sp.Name == GlobalConstants.RESISTANCES_STRING && item.WaterResistance > 0)
                    {
                        cbx.IsChecked = true;
                    }
                    break;

                case GlobalConstants.EARTH_IMAGE_PATH:
                    if (sp.Name == GlobalConstants.MASTERIES_STRING && item.EarthMastery > 0)
                    {
                        cbx.IsChecked = true;
                    }
                    if (sp.Name == GlobalConstants.RESISTANCES_STRING && item.EarthResistance > 0)
                    {
                        cbx.IsChecked = true;
                    }
                    break;

                case GlobalConstants.AIR_IMAGE_PATH:
                    if (sp.Name == GlobalConstants.MASTERIES_STRING && item.AirMastery > 0)
                    {
                        cbx.IsChecked = true;
                    }
                    if (sp.Name == GlobalConstants.RESISTANCES_STRING && item.AirResistance > 0)
                    {
                        cbx.IsChecked = true;
                    }
                    break;

                default:
                    break;
                }
            }
            return(cbx);
        }
        /// <summary>
        /// Load the item selected with formated stats to the user control for stats
        /// </summary>
        private void LoadItemToUserControlStats(EnchantedItem item, UcStatsItems uc, bool itemCanBeRemoved = false)
        {
            uc.ActualItem            = item;
            uc.LblItemName.Text      = item.Name;
            uc.LblItemLvl.Content    = "Niv." + item.Level;
            uc.LblItemRarity.Content = item.RarityName;
            uc.LblItemType.Content   = item.Type;
            uc.ImgItemPicture.Source = Tools.LoadImage(item.Image);
            uc.ImgItemRarity.Source  = Tools.LoadImage(item.RarityImage);
            uc.BtnEquip.Click       += EquipItemToBuild;
            if (itemCanBeRemoved)
            {
                uc.BtnEquip.Content     = "Modifier";
                uc.BtnRemove.Visibility = Visibility.Visible;
                uc.BtnRemove.Click     += RemoveItemToBuild;
            }

            // Customize the items of the listbox for each stats in the item loaded
            foreach (Stat stat in item.StatList)
            {
                if (stat.Type == "Coup Critique" || stat.Type == "Parade")
                {
                    stat.Type = "% " + stat.Type.Trim();
                }
                else
                {
                    // When we add the space to the stat we have to trim it first for avoiding multiple space
                    stat.Type = " " + stat.Type.Trim();
                }

                // Create stackpanel for the stats
                StackPanel sp = new StackPanel();
                sp.Orientation = Orientation.Horizontal;
                TextBlock tb = new TextBlock();
                tb.Text = stat.Value + stat.Type;
                sp.Children.Add(tb);
                uc.LbxItemStats.Items.Add(sp);

                // If the stat correspond to multiplte elements of masteries or resistances,
                // then we must create an new StackPanel with checkbox for each elements
                if (GlobalConstants.IDS_ELEM_ARRAY.Contains(stat.Id))
                {
                    sp             = new StackPanel();
                    sp.Orientation = Orientation.Horizontal;
                    // Save the actual item to the tag for recovering his properties later
                    sp.Tag = item;

                    // Define the name of the StackPanel with a string for masteries or resistances
                    // This information will be needed later
                    bool?elemForMasteries = GlobalConstants.IdForMasteriesOrResistances(stat.Id);
                    if (elemForMasteries == true)
                    {
                        sp.Name = GlobalConstants.MASTERIES_STRING;
                    }
                    else if (elemForMasteries == false)
                    {
                        sp.Name = GlobalConstants.RESISTANCES_STRING;
                    }
                    else
                    {
                        Console.WriteLine("Unknown id of masteries or resistances for the tag of the stackpanel");
                    }
                    // Add the checkbox to the stackpanel
                    int cbxFireIndex  = sp.Children.Add(CreateCheckboxElement(GlobalConstants.FIRE_IMAGE_PATH, sp, stat.Id));
                    int cbxWaterIndex = sp.Children.Add(CreateCheckboxElement(GlobalConstants.WATER_IMAGE_PATH, sp, stat.Id));
                    int cbxEarthIndex = sp.Children.Add(CreateCheckboxElement(GlobalConstants.EARTH_IMAGE_PATH, sp, stat.Id));
                    int cbxAirIndex   = sp.Children.Add(CreateCheckboxElement(GlobalConstants.AIR_IMAGE_PATH, sp, stat.Id));

                    // Check automatically the checkbox if no elements are selected
                    if ((item.FireMastery == 0 && item.WaterMastery == 0 && item.EarthMastery == 0 && item.AirMastery == 0) ||
                        (item.FireResistance == 0 && item.WaterResistance == 0 && item.EarthResistance == 0 && item.AirResistance == 0))
                    {
                        int nbElement = GlobalConstants.GetNbOfElementById(stat.Id);
                        for (int i = 0; i < nbElement; i++)
                        {
                            CheckBox cbx;
                            switch (DefaultMasteriesOrder.MasteriesOrder[i])
                            {
                            case GlobalConstants.Elementary.Fire:
                                cbx           = (CheckBox)sp.Children[cbxFireIndex];
                                cbx.IsChecked = true;
                                CbxItemElement_Click(cbx, null);
                                break;

                            case GlobalConstants.Elementary.Water:
                                cbx           = (CheckBox)sp.Children[cbxWaterIndex];
                                cbx.IsChecked = true;
                                CbxItemElement_Click(cbx, null);
                                break;

                            case GlobalConstants.Elementary.Earth:
                                cbx           = (CheckBox)sp.Children[cbxEarthIndex];
                                cbx.IsChecked = true;
                                CbxItemElement_Click(cbx, null);
                                break;

                            case GlobalConstants.Elementary.Air:
                                cbx           = (CheckBox)sp.Children[cbxAirIndex];
                                cbx.IsChecked = true;
                                CbxItemElement_Click(cbx, null);
                                break;

                            default:
                                break;
                            }
                        }
                    }
                    uc.LbxItemStats.Items.Add(sp);
                }
            }
        }