steady_progress
steady_progress

Reputation: 3731

how to get rid of namespace errors caused by including custom control in wpf application?

I am working on a wpf-project that used a ScrollViewer to show a range of items. In order to create a more advanced look and feel for the application, I replaced the Scrollviewer with a Carousel-control.

The code for the Carousel-control I downloaded from here: https://www.codeproject.com/Articles/181835/WPF-Carousel-Control

Conceptually, the carousel control (as part of my wider application) consists of a large black box (which one does not need to touch) plus just a few lines of code for plugging in the carousel control. The black box is the Carousel project, highlighted in the following screenshot:

screenshot 1

In order to plug the carousel-control in the application, just a couple of lines had to be commented out and a couple of other lines had to be added. The comments in the following two screenshots mark off the lines of code that had to be commented out and the lines of code that had to be added (in order for the scrollviewer-control to be replaced by the carousel-control): screenshot 2 ... and (at the end of the file):
screenshot 3

Furthermore, at the beginning of the xaml-file that contains the carousel, the following line was included:

xmlns:Carousel="clr-namespace:Carousel;assembly=Carousel"

as can be seen in the following screenshot:

enter image description here

As you can see, at the moment, the code for the scrollviewer is commented out. Hence, the application is using the Carousel at the moment.

This carousel works fine. However, the error list shows a bunch of errors, mostly of the following type:

the name "XYZ" does not exist in the namespace "bla".   

The following screenshot shows some of the error messages:

screenshot 5

As already mentioned, the carousel-control works despite those error messages. However, I still need to get rid of the error messages before leaving this project.

Regarding the error messages, the following points might be of interest:

  1. No error messages are shown, when the scrollviewer-control is used.
  2. As you can see from screenshot 5, most error messages refer to line 1 of the file CarouselControl.xaml. This file is located inside the "black box":

screenshot 6

The beginning of file CarouselControl.xaml contains the following lines of code:

screenshot 7

  1. As you can see from screenshot 5, most of the error messages say that some name or property does not exist in namespace xyz, whereby namespace xyz is one of the namespaces listed at the beginning of file CarouselControl.xaml (see screenshot 7).

********************************UPDATE*****************************************

(Right-click on) Solution -> Properties -> Configuration Properties, I noticed that it was apparently not possible to change the configuration of the Carousel-project to anything other than platform x86:

enter image description here

No matter which platform I selected (from the drop down menu at the top of the screenshot), the platform for the Carousel-project stubbornly remained at value "x86". Might this have something to do with the error messages?

Upvotes: 0

Views: 93

Answers (1)

Jack
Jack

Reputation: 996

I'm not sure how useful this may be, but I believe I have found the code that was the source of my problem:

        var variables = values[0] as ObservableCollection<variable>;
        var identifier = values[1] as string;

        var variable = variables.SingleOrDefault(x => x.identifier == identifier);

        if (variable == null) return "";

This is code of my converter to access a variable in a collection and return its value as a string, it was used on a TextBox control.

Looking back over my branches, it seems that I made this change:

var variable = variables?.SingleOrDefault(x => x.identifier == identifier);

Resharper suggested adding a Null-conditional Operator at this point, which solved my issue. It would seem that the designer was returning errors due to the LINQ expression, since the collection at this point was uninitialized.

I would look through your code to see if you have a similar instance of uninitialized collections.

Upvotes: 1

Related Questions