question

SudharsanNarayanan-9560 avatar image
0 Votes"
SudharsanNarayanan-9560 asked HuiLiu-MSFT commented

CustomControl TargetType does not match type of element throws error in WPF designer

126370-designer-issue.pngHi,

I have created a custom control in WPF. While working with that custom control in WPF designer, it is throwing "TargetType does not match the type of element" in the designer. But I'm getting a visual studio designer exception using the WPF Controls library. Styles are in another project and the ResourceDictionary is Merged in app.xaml.

I have also noticed that the issue only happens when selecting x64 as the active solution platform as opposed to the default Any CPU, but this also means that I have to switch change from x64 when running in Debug mode.


dotnet-csharpwindows-wpfdotnet-wpf-xaml
designer-issue.png (97.0 KiB)
· 9
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,@ SudharsanNarayanan-9560. Could you show me the code of your CustomControl? What is the Platform target of your CustomControl? And what is the code of your TextBoxStyle2?

0 Votes 0 ·

Hi @HuiLiu-MSFT ,

Thanks for the update,

My sample code: https://1drv.ms/u/s!Ar1ZZ5lsIm1TcJuqPEfPvrWcQZc?e=OLNKr0

Regards,
Sudharsan

0 Votes 0 ·
HuiLiu-MSFT avatar image HuiLiu-MSFT SudharsanNarayanan-9560 ·

I did not reproduce your problem, I got the following display with your code.
126569-4.png
For projects that target ARM or X64 processors, Visual Studio cannot run project code in the designer. (Quoting from Note in document To disable project code in the designer)
Please try the following if it works for you. If you have any questions, please let me know.
You could set the Platform of WpfApp1(Custom Control) to AnyCPU( Click Configuration Manager... under the Build menu).
126630-6.png

Then the designer can display normally.
126609-5.png


0 Votes 0 ·
4.png (60.9 KiB)
6.png (20.5 KiB)
5.png (20.0 KiB)
Show more comments

0 Answers