title: Visual Studio XAML Designer error XDG0062 using EventSetter in .NET Core WPF application
body: <p>While porting a WPF project from .NET Framework to .NET Core I ran into a problem with the XAML-Designer in VS2019 <code>v16.3.10</code>. It keeps throwing <code>XDG0062</code> errors when I try to use <code>EventSetter</code> in styles. The code compiles and runs fine, but the errors cause the concerned elements in the designer to be replaced by a red circle with an X, making designing a UI rather hard. The same XAML works fine in a .NET <code>framework 4.7.2.</code> project.</p>
  <p>To track down the problem I made a VS minimal project (WPF .NET Core) from scratch and the problem occurs here as well (see errors and code below). It seems to be caused by the use of <code>EventSetter</code> in styles - unfortunately I have no clue why. Google yielded one mention of the problem without a solution, Stack Overflow has one topic on this error code, however, the solution suggested there (deleting VS cache) didn´t help. Deleting the <code>EventSetter</code> line removes both error messages.</p>
  <p>Does anyone have a suggestion to solve this?</p>
  <p><strong>Full error messages:</strong></p>
  <pre><code>Line 9: XDG0062 Non-NULL value required for &quot;EventSetter.Handler&quot;
  
  Line 12: XDG0062 Value cannot be null. (Parameter 'typeDescriptorContext')
  </code></pre>
  <p><strong>XAML:</strong></p>
  <pre><code>&lt;Window x:Class=&quot;XDG0062_test.MainWindow&quot;
      xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
      xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
      xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
      xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
      xmlns:local=&quot;clr-namespace:XDG0062_test&quot;
      mc:Ignorable=&quot;d&quot;
      Title=&quot;MainWindow&quot; Height=&quot;450&quot; Width=&quot;800&quot;&gt;
      &lt;Window.Resources&gt;
          &lt;Style TargetType=&quot;TextBox&quot;&gt;
              &lt;Setter Property=&quot;Height&quot; Value=&quot;30&quot;&gt;&lt;/Setter&gt;
              &lt;Setter Property=&quot;Width&quot; Value=&quot;130&quot;&gt;&lt;/Setter&gt;
              &lt;EventSetter Event=&quot;GotFocus&quot; Handler=&quot;TextBox_GotFocus&quot;/&gt;
          &lt;/Style&gt;
      &lt;/Window.Resources&gt;
      &lt;Grid&gt;
          &lt;TextBox HorizontalAlignment=&quot;Left&quot; Margin=&quot;70,100,0,0&quot;
                   Text=&quot;TextBox&quot; TextWrapping=&quot;Wrap&quot; VerticalAlignment=&quot;Top&quot;/&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  <p><strong>C#:</strong></p>
  <pre><code>using System.Windows;
  namespace XDG0062_test
  {
      public partial class MainWindow : Window
      {
          public MainWindow()
          {
              InitializeComponent();
          }
          private void TextBox_GotFocus(object sender, RoutedEventArgs e)
          {
              MessageBox.Show(&quot;Beep&quot;);
          }
      }
  }
  </code></pre>