Using directive works...and doesn't.

Magnus Vinterhav 61 Reputation points
2020-12-30T17:01:58.857+00:00

I am using core 3.1 and am writing a WPF application.
Visual Studio Community 2019 with all updates applied.
All project are using core 3.1 and in the csproj files I have <UseWPF>true</UseWPF>
I am also using a nuget package called "WriteableBitmapEx" Version="1.6.7"

In the xaml.cs file it works fine to use colors like this:
****listOfColors.Add(System.Windows.Media.Color.FromArgb((byte)0, (byte)i, (byte)i, (byte)i));****
includes are:
using System;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Collections.Generic;
using StructureLibrary;

No problem there.
In another project which also uses core 3.1, I have the same includes, but the following happens.
When I write for example ****Color c = new System.Windows.Media.Color****
and checks the "using" includes for Color by going to definition, I find the definition, no problems, among these definitions are
public static Color FromRgb(byte r, byte g, byte b);

BUT when I try to continue my line above with ****Color c = new System.Windows.Media.Color.FromArgb((byte)0, (byte)x, (byte)y, (byte)255)****
intellisense can't find any FromArgb method.

It seems as if the using directive works, because I can see the definition, but it doesn't work, because I can't use it. Intellisense can't find the "FromArgb" method.

What am I doing wrong?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,755 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,815 questions
{count} votes

Accepted answer
  1. Peter Fleischer (former MVP) 19,321 Reputation points
    2020-12-30T17:54:50.13+00:00

    Hi Magnus,
    FromArgb is a static method. Don't use keyword "new".

    Color c = System.Windows.Media.Color.FromArgb((byte)0, (byte)x, (byte)y, (byte)255);
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.