提问人:Leonardo Moreira 提问时间:12/16/2021 最后编辑:Bas HLeonardo Moreira 更新时间:12/17/2021 访问量:222
当我在 TextBox 中编写时,我在 WPF 中出现错误“窗口标识符无效”
When I write in a TextBox I have a error 'The window identifier is invalid ' in WPF
问:
我正在做一个没有数据库的简单“Crud”,当我在项目的任何 textBox 中编写任何内容时,我都会抛出异常。
System.ComponentModel.Win32Exception: '窗口句柄无效',
这只有在我在文本框中写入时才会发生,我在 Stack Overflow 上没有找到任何类似的问题。如果有人能帮助我,我将不胜感激。完整的错误是这样的:
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()
注意:我从昨天开始就一直遇到这个错误,但是当我今天打开计算机时,它没有发生。它在运行几次后开始,就像昨天开始一样,但现在即使我重新启动电脑,它也能运行
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>
答:
2赞
Leonardo Moreira
12/17/2021
#1
我终于在这个链接上找到了答案: 解决方案
这个解决方案基本上对我有帮助,在你的Visual Studio中,你应该转到“工具”>“选项”>“调试”>“常规”>,并禁用“适用于XAML的UI接口调试工具”选项。
希望能帮助有同样问题的人。
上一个:尝试制作有异常的计算器
评论