0

I am making a league of legends simulator. The app simulates a 5V5 or a 3V3 match where randomly Champions will load into 2 teams. To fill the image of a champion (comparable with a loadingscreen) I have a method called 'Genereer5v5Button_Click'. This method is called when a user clicks on a button, this will fill 2 List of 5 random Champions.

Now when I click the button nothing happens , the images are not showing and no error is thrown. Can somebody look at my code, there is probably something wrong with the path I am passing because when I am debugging the path is filled in (Maybe something with Relative/Absolute).

private void Genereer5v5Button_Click(object sender, RoutedEventArgs e)
        {
            if (!String.IsNullOrEmpty(PasswordBoxMatchCode.Password))
            {
                if (MatchData.IsUniqueCode(PasswordBoxMatchCode.Password).Equals(true))
                {
                    currentMatch = new SummonersRift(PasswordBoxMatchCode.Password);
                    currentMatch.GenereerTeams();
                    ImageIconChampion1Team1.Source = ReturnSourceTeam1()[0];
                    ImageIconChampion2Team1.Source = ReturnSourceTeam1()[1];
                    ImageIconChampion3Team1.Source = ReturnSourceTeam1()[2];
                    ImageIconChampion4Team1.Source = ReturnSourceTeam1()[3];
                    ImageIconChampion5Team1.Source = ReturnSourceTeam1()[4];

                    ImageIconChampion1Team2.Source = ReturnSourceTeam2()[0];
                    ImageIconChampion2Team2.Source = ReturnSourceTeam2()[1];
                    ImageIconChampion3Team2.Source = ReturnSourceTeam2()[2];
                    ImageIconChampion4Team2.Source = ReturnSourceTeam2()[3];
                    ImageIconChampion5Team2.Source = ReturnSourceTeam2()[4];
                }
                else
                {
                    MessageBox.Show("Deze code is reeds gebruikt. Kies een andere.");
                }
            }
            
            else
            {
                MessageBox.Show("Geef een code mee", "Geen code");
            }
        }
private List<ImageSource> ReturnSourceTeam1()
        {
            List<ImageSource> sources = new List<ImageSource>();
            foreach (var champ in currentMatch.Team1Champions)
            {

                Uri uri = new Uri($"images/{champ.IconSource}", UriKind.Relative);

                ImageSource imgSource = new BitmapImage(uri);
                sources.Add(imgSource);

            }
            

            return sources;
        }
  • This was my first post , didnt know you could pass it as a block of code with ```...Code...``` – ImperialHalCodes Jun 01 '22 at 19:47
  • First of all, is `Genereer5v5Button_Click` even firing? – mxmissile Jun 01 '22 at 19:50
  • Yes i debugged on the click event, btw this is my first year of coding – ImperialHalCodes Jun 01 '22 at 19:51
  • Step through the event, does the expected code get hit? – mxmissile Jun 01 '22 at 19:52
  • Yes every method is called once you click the button, i went trough it step by step and the path is filled in as I describe it. I think its something with the BaseUri infront of the relative path – ImperialHalCodes Jun 01 '22 at 19:55
  • The image files would usually be part of your Visual Studio project - e.g. in a project folder named `images` - and you would set their Build Action to `Resource`. Then load them from Resource File Pack URIs as shown in the answers to the duplicate questions. – Clemens Jun 01 '22 at 20:12

0 Answers0