。NET Core WPF应用程序中使用EventSetter的Visual Studio XAML Designer错误XDG0062

问题描述 投票:2回答:1

当将WPF项目从.NET Framework移植到.NET Core时,我遇到了VS2019(v16.3.10)中XAML-Designer的问题。当我尝试在样式中使用EventSetter时,它总是抛出“ XDG0062”错误。代码可以编译并正常运行,但是错误导致设计器中的相关元素被替换为带有X的红色圆圈,这使得设计UI变得相当困难。相同的XAML在.NET Framework 4.7.2中可以正常工作。项目。

为了跟踪问题,我从头开始制作了一个VS最小项目(WPF .NET Core),并且这里也发生了问题(请参见下面的错误和代码)。这似乎是由于EventSetter的使用方式引起的-不幸的是,我不知道为什么。 Google提到了没有解决方案的问题,Stack Overflow对此错误代码有一个话题,但是,那里提出的解决方案(删除VS缓存)没有帮助。删除EventSetter行会同时删除两条错误消息。

有人有解决这个问题的建议吗?

完整的错误消息:

第9行:“ EventSetter.Handler”需要XDG0062非NULL值

第12行:XDG0062值不能为null。 (参数“ typeDescriptorContext”)

XAML

<Window x:Class="XDG0062_test.MainWindow"
    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:XDG0062_test"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="800">
<Window.Resources>
    <Style TargetType="TextBox">
        <Setter Property="Height" Value="30"></Setter>
        <Setter Property="Width" Value="130"></Setter>
        <EventSetter Event="GotFocus" Handler="TextBox_GotFocus" />
    </Style>
</Window.Resources>

<Grid>
    <TextBox HorizontalAlignment="Left" Margin="70,100,0,0" Text="TextBox" TextWrapping="Wrap" VerticalAlignment="Top"/>
 </Grid>

C#

using System.Windows;

namespace XDG0062_test
{

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void TextBox_GotFocus(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Beep");
        }
    }
}
wpf visual-studio xaml designer eventsetter
1个回答
-1
投票
中使用EventSetter时,它不断抛出“ XDG0062”错误

Microsoft已发布注释中提到的修复程序。我可以确认自VS 2019 16.5.0起我的问题确实已解决]

© www.soinside.com 2019 - 2024. All rights reserved.