Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trying to get example from Microsoft Docs on WPF to work in local machine

I’d like to get this example running from the Microsoft Docs.

In order to do so I made a new directory called inotifyproperty-changed-example. In this project I generated a WPF solution by running the following commands:

dotnet new wpf
dotnet new sln
dotnet sln add inotifyproperty-changed-example.csproj

Then I removed all XAML and CS files by running rm *.cs; rm*.xaml as it is my understanding the example code is self-contained.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Then I copied the example code in the link to a file called App.cs and changed the namespace to match my own, namely inotifyproperty_changed_example.

The contents of the CSPROJ file are as follows:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <RootNamespace>inotifyproperty_changed_example</RootNamespace>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

</Project>

Unfortunately when I try to run the solution using dotnet run I get errors:

error CS0234: The type or namespace name ‘Forms’ does not exist in the namespace ‘System.Windows’ (are you missing an assembly reference?)
The type or namespace name ‘Form’ could not be found (are you missing a using directive or an assembly reference?)

I’m really at a loss as to why this won’t build. More generally speaking, I am asking this question because I’m unable to reproduce many of the examples provided in the WPF documentation, so I need a place to start.

How can I get the example to work?

>Solution :

You are linking to a Windows Forms example, not a WPF one.

Create the WPF project using the default template and don’t remove any files. Then add the DemoCustomer class from the example to the project. You cannot use the Form1 class as it’s not WPF. Instead you could modify the MainWindow class as per your requirements.

As far as the INotifyPropertyChanged interface is concerned, there is no difference between WPF and Windows Forms. This interface is not platform specific.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading