I am doing a Simple "Crud" without database, and when i write anything in any of my textBox of my project i have an exception getting thrown.
System.ComponentModel.Win32Exception: 'Window handle is invalid',
This only happens when I write in the textbox, I didn't find any similar question here on Stack Overflow. If someone can help me I'll be very grateful. The complete error is this one:
System.ComponentModel.Win32Exception
HResult=0x80004005
Message=Window identifier is invalid
Source=WindowsBase
StackTrace:
at MS.Win32.UnsafeNativeMethods.GetMessageW(MSG& msg, HandleRef hWnd, Int32 uMsgFilterMin, Int32 uMsgFilterMax)
at System.Windows.Threading.Dispatcher.GetMessage(MSG& msg, IntPtr hwnd, Int32 minMessage, Int32 maxMessage)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at Microsoft.VisualStudio.DesignTools.WpfTap.WpfVisualTreeService.VisualTree.RootSourceFinder.HwndWatcher()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Note: this error I've been having since yesterday, but when I turned on the computer today it wasn't happening. It started after a few runs, the same way it started yesterday, but now even if I restart the pc, it's running
CreateWindow.xalm:
<Window x:Class="Atividade_1_Luz.CreateView"
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:Atividade_1_Luz"
mc:Ignorable="d"
Title="CreateView" Height="450" Width="800">
<Grid >
<StackPanel Background="AliceBlue" Orientation="Vertical" Margin="295,60,307,62">
<TextBlock FontSize="15" TextAlignment="Center" HorizontalAlignment="Center" Margin="0,10,0,0" TextWrapping="Wrap" Text="Register Product" VerticalAlignment="Top" Height="28" Width="138"/>
<Label VerticalContentAlignment="Center" HorizontalAlignment="Center" Margin="10,5,10,0" Width="100" Height="30" Content="Name" FontSize="10"/>
<TextBox Margin="25,-10,28,5" Height="24" Width="100" Text="{Binding Name}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
/>
<Label VerticalContentAlignment="Center" HorizontalAlignment="Center" Margin="10,5,10,0" Width="100" Height="30" Content="Category" FontSize="10"/>
<TextBox Margin="25,-10,28,5" Height="24" Width="100" TextWrapping="Wrap" Text="{Binding Category}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
/>
<Label VerticalContentAlignment="Center" HorizontalAlignment="Center" Margin="10,5,10,0" Width="100" Height="30" Content="Description" FontSize="10"/>
<TextBox Margin="25,-10,28,5" Height="24" Width="100" TextWrapping="Wrap" Text="{Binding Description}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
/>
<Label VerticalContentAlignment="Center" HorizontalAlignment="Center" Margin="10,5,10,0" Width="100" Height="30" Content="Price" FontSize="10"/>
<TextBox Margin="25,-10,28,5" Height="24" Width="100" TextWrapping="Wrap" Text="{Binding Price}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
/>
<StackPanel Orientation="Horizontal" Height="45">
<Button Command="{Binding Command}" Width="50" HorizontalAlignment="Left" Height="20" VerticalAlignment="Center" Content="Back" Margin="30,0,10,0"/>
<Button Command="{Binding CommandCreate}" Width="50" HorizontalAlignment="Left" Height="20" VerticalAlignment="Center" Content="Create" Margin="20,0,10,0"/>
</StackPanel>
</StackPanel>
<Border CornerRadius="10" BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="299" Margin="295,60,0,0" VerticalAlignment="Top" Width="192"/>
</Grid>
</Window>
UpdateWindow.xalm:
<Window x:Class="Atividade_1_Luz.UpdateView"
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:Atividade_1_Luz"
mc:Ignorable="d"
Title="UpdateView" Height="450" Width="800">
<Grid>
<StackPanel Background="AliceBlue" Orientation="Vertical" Margin="295,60,307,62">
<TextBlock FontSize="15" TextAlignment="Center" HorizontalAlignment="Center" Margin="0,10,0,0" TextWrapping="Wrap" Text="Update Product" VerticalAlignment="Top" Height="28" Width="138"/>
<Label VerticalContentAlignment="Center" HorizontalAlignment="Center" Margin="10,5,10,0" Width="100" Height="30" Content="Name" FontSize="10"/>
<TextBox Margin="25,-10,28,5" Height="24" Width="100" Text="{Binding Name}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
/>
<Label VerticalContentAlignment="Center" HorizontalAlignment="Center" Margin="10,5,10,0" Width="100" Height="30" Content="Category" FontSize="10"/>
<TextBox Margin="25,-10,28,5" Height="24" Width="100" TextWrapping="Wrap" Text="{Binding Category}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
/>
<Label VerticalContentAlignment="Center" HorizontalAlignment="Center" Margin="10,5,10,0" Width="100" Height="30" Content="Description" FontSize="10"/>
<TextBox Margin="25,-10,28,5" Height="24" Width="100" TextWrapping="Wrap" Text="{Binding Description}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
/>
<Label VerticalContentAlignment="Center" HorizontalAlignment="Center" Margin="10,5,10,0" Width="100" Height="30" Content="Price" FontSize="10"/>
<TextBox Margin="25,-10,28,5" Height="24" Width="100" TextWrapping="Wrap" Text="{Binding Price}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
/>
<StackPanel Orientation="Horizontal" Height="45">
<Button Command="{Binding Command}" Width="50" HorizontalAlignment="Left" Height="20" VerticalAlignment="Center" Content="Back" Margin="30,0,10,0"/>
<Button Command="{Binding CommandCreate}" Width="50" HorizontalAlignment="Left" Height="20" VerticalAlignment="Center" Content="Create" Margin="20,0,10,0"/>
</StackPanel>
</StackPanel>
<Border CornerRadius="10" BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="299" Margin="295,60,0,0" VerticalAlignment="Top" Width="192"/>
</Grid>
</Window>
I don't know if this is normal, but there's no problem with this line not being used?