Switch Statement based on value of another Window.


Mar 16, 2017
Programming Experience
I have 2 Windows. Window1 & Window2.

Window 1 has 2 check boxes. Mcheck and Fcheck
Window 2 has 2 combo boxes. Race and Class.

The goal, is on Window 2 when all 3 have been selected an image appears. For example.

Case: Mcheck is checked
Case: Race is Human
Case: Class is Barbarian

Show MHumanBarbarian image.

(This is kind of like a character select menu from a video game). Not sure how to do this while getting the info from a different window.

Here is what I have for a single case which works fine, but I need the other options in there.

private void Race_SelectionChanged(Object sender, SelectionChangedEventArgs e)
            ComboBoxItem selectedItem = (ComboBoxItem)Race.SelectedItem;
            //Sets Races default visibility to false
            StatsDwarf.Visibility = Visibility.Hidden;
            StatsHuman.Visibility = Visibility.Hidden;
            StatsGnome.Visibility = Visibility.Hidden;
            StatsElf.Visibility = Visibility.Hidden;
            StatsHalfElf.Visibility = Visibility.Hidden;
            StatsHalfOrc.Visibility = Visibility.Hidden;
            StatsHalfling.Visibility = Visibility.Hidden;
            StatsDragonborn.Visibility = Visibility.Hidden;
            StatsTiefling.Visibility = Visibility.Hidden;
            StatsHillDwarfLabel.Visibility = Visibility.Hidden;
            StatsHillDwarf1.Visibility = Visibility.Hidden;
            StatsHillDwarf2.Visibility = Visibility.Hidden;
            StatsHillDwarf3.Visibility = Visibility.Hidden;
            StatsDragonbornLabel.Visibility = Visibility.Hidden;
            StatsDragonbornBlue.Visibility = Visibility.Hidden;
            StatsDragonbornblack.Visibility = Visibility.Hidden;
            StatsDragonboneWhite.Visibility = Visibility.Hidden;
            StatsDragonboneSilver.Visibility = Visibility.Hidden;
            StatsDragonboneRed.Visibility = Visibility.Hidden;
            StatsDragonboneGreen.Visibility = Visibility.Hidden;
            StatsDragonboneGold.Visibility = Visibility.Hidden;
            StatsDragonboneCopper.Visibility = Visibility.Hidden;
            StatsDragonboneBronze.Visibility = Visibility.Hidden;
            StatsDragonboneBrass.Visibility = Visibility.Hidden;
            StatsHighElf2.Visibility = Visibility.Hidden;
            StatsHighElf1.Visibility = Visibility.Hidden;
            StatsHighelfLabel.Visibility = Visibility.Hidden;
            StatsHighElf3.Visibility = Visibility.Hidden;
            StatsHighElf4.Visibility = Visibility.Hidden;
            StatsRockgnomelabel.Visibility = Visibility.Hidden;
            StatsRockgnome1.Visibility = Visibility.Hidden;
            StatsRockgnome2.Visibility = Visibility.Hidden;
            StatsRockgnome3.Visibility = Visibility.Hidden;
            StatsLightfootlabel.Visibility = Visibility.Hidden;
            StatsLightfoot1.Visibility = Visibility.Hidden;
            StatsLightfoot2.Visibility = Visibility.Hidden;
            subracetext.Visibility = Visibility.Visible;
            MDT.Visibility = Visibility.Hidden;
            FDT.Visibility = Visibility.Hidden;

            switch (selectedItem.Content.ToString())
                case "Dwarf":
                    StatsDwarf.Visibility = Visibility.Visible;
                    StatsHillDwarfLabel.Visibility = Visibility.Visible;
                    StatsHillDwarf1.Visibility = Visibility.Visible;
                    StatsHillDwarf2.Visibility = Visibility.Visible;
                    StatsHillDwarf3.Visibility = Visibility.Visible;
                    MDT.Visibility = Visibility.Visible;
                case "Human":
                    StatsHuman.Visibility = Visibility.Visible;
                    FDT.Visibility = Visibility.Visible;
                case "Gnome":
                    StatsGnome.Visibility = Visibility.Visible;
                    StatsRockgnomelabel.Visibility = Visibility.Visible;
                    StatsRockgnome1.Visibility = Visibility.Visible;
                    StatsRockgnome2.Visibility = Visibility.Visible;
                    StatsRockgnome3.Visibility = Visibility.Visible;
                case "Elf":
                    StatsElf.Visibility = Visibility.Visible;
                    StatsHighElf2.Visibility = Visibility.Visible;
                    StatsHighElf1.Visibility = Visibility.Visible;
                    StatsHighelfLabel.Visibility = Visibility.Visible;
                    StatsHighElf3.Visibility = Visibility.Visible;
                    StatsHighElf4.Visibility = Visibility.Visible;
                case "Half-Elf":
                    StatsHalfElf.Visibility = Visibility.Visible;
                case "Half-Orc":
                    StatsHalfOrc.Visibility = Visibility.Visible;
                case "Halfling":
                    StatsHalfling.Visibility = Visibility.Visible;
                    StatsLightfootlabel.Visibility = Visibility.Visible;
                    StatsLightfoot1.Visibility = Visibility.Visible;
                    StatsLightfoot2.Visibility = Visibility.Visible;
                case "Dragonborn":
                    StatsDragonborn.Visibility = Visibility.Visible;
                    StatsDragonbornLabel.Visibility = Visibility.Visible;
                    StatsDragonbornBlue.Visibility = Visibility.Visible;
                    StatsDragonbornblack.Visibility = Visibility.Visible;
                    StatsDragonboneWhite.Visibility = Visibility.Visible;
                    StatsDragonboneSilver.Visibility = Visibility.Visible;
                    StatsDragonboneRed.Visibility = Visibility.Visible;
                    StatsDragonboneGreen.Visibility = Visibility.Visible;
                    StatsDragonboneGold.Visibility = Visibility.Visible;
                    StatsDragonboneCopper.Visibility = Visibility.Visible;
                    StatsDragonboneBronze.Visibility = Visibility.Visible;
                    StatsDragonboneBrass.Visibility = Visibility.Visible;
                    subracetext.Visibility = Visibility.Hidden;
                case "Tiefling":
                    StatsTiefling.Visibility = Visibility.Visible;
Are Mcheck and Fcheck for male and female? If so then shouldn't they be RadioButtons rather than CheckBoxes?

As for the question, what is the relationship between the two windows? Is Window1 displaying Window2? If so, is it displaying it as a modal dialogue?

By the way, please post your WPF questions in the WPF forum. You should only be posting in a General forum if there isn't a more specific forum that is appropriate. I have moved this thread.
Thanks for you time and moving that for me, I will make sure all future posts related to this project are in the WPF section.

They are for Male and Female, and making them radials would be no problem.

So I am "Average" with VB.net and Win Forms, however this is my 1st project with WPF as well as teaching myself C# so I might be going about this completely wrong. I think it will make more sense If I give you a run down of the entire thing.

Not sure if you ever played D&D but essentially what I am trying to create is a Character Manager. The initial window pops up with 2 options. New and Load. When you press new a window pops up asking for your Character Name, Sex, Age, Hair, etc etc. Once you fill that in you hit continue and a new window pops up. This window you roll all your stats, skills etc. You hit continue again and we get to the select class and race. (Which is where I am inquiring.) At the conclusion of the windows, you will get to a main character screen that will grab all the info you provided and give you a Character Screen. I have not figured out how to convert all the info over to the main window yet as I am still on the build a character process.

This is the code I use for each window transition or "Continue" button. I will also attach some screen shots to make more sense of it.

private void Image_MouseUp(object sender, MouseButtonEventArgs e)
            Create2 c2 = new Create2();


Each image shows is a new window using the same code as above. Eventually all the info entered into all the windows will go into one main page. Which Load character will take you too.

** The more I think about it using this.Close(); would wipe out any info they entered right? Not sure the best way to go about this.
Top Bottom