There is XAML code and there is a class CustomVisualFrameworkElement , which is inherited from FrameworkElement and implements some shapes using Visual . But for some reason, XAML does not see this class, although I connect the space that contains the class CustomVisualFrameworkElement

XAML CODE:

 <Window x:Class="RenderingWithVisuals.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:RenderingWithVisuals" //Вот тут я подключаю пространство в котором находится класс CustomVisualFrameworkElement mc:Ignorable="d" Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded"> <StackPanel Name="MyStackPAnel"> <Image Height="80" Name="MyImage" /> <!--Теперь используем наш класс, который содержит в себе фигуры и инфраструктуру от FrameworkElement--> <custom: CustomVisualFrameworkElement/> //Вот тут не видит класс </StackPanel> </Window> 

enter image description here

enter image description here

  • Not. unknown team ... - batya
  • @FoggyFinder, updated the question - batya
  • @batya: You have xmlns:local declared there, and in fact you use custom:CustomVisualFrameworkElement . - VladD
  • @FoggyFinder, I told you the same problem with loacl. Proof in question. - batya
  • one
    @batya: And if you do this: (1) Remove <local:CustomVisualFrameworkElement/> from XAML, (2) Recompile the project and make sure it compiles without errors, (3) Add <local:CustomVisualFrameworkElement/> back? - VladD

1 answer 1

If the code is OK, the following algorithm helps:

  1. Remove <local:CustomVisualFrameworkElement/> from XAML,
  2. Recompile the project and make sure that it compiles without errors,
  3. Add <local:CustomVisualFrameworkElement/> back.

Exposing the magic: WPF compiles the project in two passes: first XAML (this generates C # code), then the entire code-behind. If you have a fresh class in the code-behind, which is mentioned in XAML, then when you compile XAML, it is not yet visible, and the first compilation stage fails. Removing a new element, we give the first stage of compilation to complete, and the compiler finally sees a new class.

Yes, this is a bug in Visual Studio.

  • 2
    You can switch the debug / release and compile, then switch back. It works that way too. - Andrei NOP
  • @Andrey: Cool, did not know. If the project is small, it may be faster, by the way. - VladD