lte__ lte__ - 1 year ago 289
C# Question

C# WPF - MainWindow content gets shown in two separate windows instead of one

I want to have a single

with two columns, a narrow one on the left and a wide one on the right. In the left one should be a menubar and in the right one a grid of
(which is a custom
). However, right now when I launch the program, it gives me two windows, one with the grid and one with the menubar on the left. What am I doing wrong? Where might be the error?

Tha XAML looks like this:

<Window x:Class="SavageMaci.MainWindow"
Title="Test" Height="500" Width="700">
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />

<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />

<Menu Grid.Row="1" Grid.Column="1" Margin="38,0,187,430" Background="White">
<RotateTransform Angle="90"/>
</Menu.RenderTransform >
<MenuItem Header="Level 1" FontFamily="Roboto" Height="32" Width="65"/>
<MenuItem Header="Level 2" FontFamily="Roboto" Height="32" Width="65"/>
<MenuItem Header="Level 3" FontFamily="Roboto" Height="32" Width="65"/>
<ItemsControl Grid.Row="1" Grid.Column="2" ItemsSource="{Binding Fields}">
<UniformGrid Rows="{Binding Size}" Columns="{Binding Size}"/>

The xaml.cs is also basic:

namespace SavageMaci
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
public MainWindow()

There's only one reference to
, in
, where I instantiate it. Please let me know where else might the error be, I'll update the question with that code, too. Thank you for helping!

Answer Source

The solution to your problem is simple. In your App class, you create a MainWindow instance.

This is unnecessary since App creates its own instance whether you create it or not.

Have a look at the App.xaml file and you will see for yourself.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download