ScottBeebiWan
ScottBeebiWan

Reputation: 119

Second WPF window is blank

The second window in my WPF window is blank.

I've tried declaring the variable in multiple places, and assigning the value of new Send() separately from the declaration.

I've also made sure it isn't just my computer. I sent the compiled program to someone else and it did the same thing.

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Send send = new Send();
            send.Show();
        }

The Send class:

    public partial class Send : Window
    {
        public Send()
        {
            InitializeComponent();
            ipIdBox.Text = GenerateIPID(GetIPAddress(), 8000);
        }

        private string GetIPAddress()
        {
            var host = Dns.GetHostEntry(Dns.GetHostName());
            foreach (var ip in host.AddressList)
            {
                if (ip.AddressFamily == AddressFamily.InterNetwork)
                {
                    return ip.ToString();
                }
            }
            throw new Exception("No network adapters with an IPv4 address in the system!");
        }

        private string GenerateIPID(string ip, int port)
        {
            string[] ipseps = ip.Split('.'); // Split IP into parts
            string code = ""; // Initialize the code
            int counter = 0; // A counter (because every 4 digits are seperated)
            foreach (string ippart in ipseps)
            {
                int ipparti = Convert.ToInt32(ippart);
                string hippart = ipparti.ToString("X2");
                code += hippart;
                counter++;
                if (counter == 1) {
                    counter = 0;
                    code += "-";
                }
            }
            code += $"-{port.ToString("X4")}";
            return code;
        }

    }

... and it's XAML

<Window x:Class="ScistMain.Send"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:ScistMain"
        mc:Ignorable="d"
        Title="Send" Height="264.95" Width="451.774" OverridesDefaultStyle="True" Topmost="True">
    <Grid>
        <TextBlock x:Name="ipIdBox" Margin="0,124,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="34" TextAlignment="Center" FontSize="24" Text="7F00-0001-8000"/>
        <TextBlock Margin="0,108,0,0" TextWrapping="Wrap" Text="Tell the person recieving to type this code:" VerticalAlignment="Top" Width="444" TextAlignment="Center"/>
        <TextBlock Margin="0,10,0,0" TextWrapping="Wrap" Text="You are sending:" VerticalAlignment="Top" TextAlignment="Center" FontSize="18" FontWeight="Bold"/>
        <Image x:Name="iconImg" Height="32" Margin="206,39,206,0" VerticalAlignment="Top" Width="32" Source="Resources/scist.ico"/>
        <TextBlock Margin="0,76,0,0" TextWrapping="Wrap" Text="Placeholder Program" VerticalAlignment="Top" TextAlignment="Center"/>
        <ProgressBar x:Name="pBar" HorizontalAlignment="Left" Height="34" Margin="10,124,0,0" VerticalAlignment="Top" Width="424" Visibility="Collapsed"/>
        <Button Content="Cancel" HorizontalAlignment="Left" Margin="359,203,0,0" VerticalAlignment="Top" Width="75"/>

    </Grid>
</Window>

I expect it to show the window I created in the designer:

but instead it shows a black window.

Upvotes: 2

Views: 734

Answers (1)

ScottBeebiWan
ScottBeebiWan

Reputation: 119

OverridesDefaultStyle="True" on the Window tag was the issue.

Upvotes: 1

Related Questions