Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio XAML Designer error XDG0062 using EventSetter in .NET Core WPF application

While porting a WPF project from .NET Framework to .NET Core I ran into a problem with the XAML-Designer in VS2019 v16.3.10. It keeps throwing XDG0062 errors when I try to use EventSetter 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 framework 4.7.2. project.

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 EventSetter 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 EventSetter line removes both error messages.

Does anyone have a suggestion to solve this?

Full error messages:

Line 9: XDG0062 Non-NULL value required for "EventSetter.Handler"

Line 12: XDG0062 Value cannot be null. (Parameter '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>
</Window>

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");
        }
    }
}
like image 940
BBockisch Avatar asked Nov 26 '19 13:11

BBockisch


1 Answers

I solved this by deleting the folder .vs/$(SolutionName)/DesignTimeBuild, so I can keep VS configuration/explorer/tabs, which are lost when deleting the whole .vs.

like image 159
Soleil Avatar answered Sep 23 '22 06:09

Soleil