Proplems due to Copying a WPF Solution - InitializeComponent() not found - c#

I have a Working and Compileable WPF-Solution in a which I needed to copy to another directory.
Now I experience the following Problem, which I nowhere found similar on the web:
In some Projects every UserControl I created, isnt compileable anymore. Somehow Terms like DataContext or InitializeComponent() "do not exist in the current context".
Usually this is a case of wrong namespaces, or classnaming between the xaml and xaml.cs. As my code is all compileable in the original repo, this can not be the case. I've also checked that build action is set to Page, which is also a common issue in this case.
As I've found out, even newly created UserControls have the same problems. So I compared the projectfiles from the source and targed destination, which seemed to have no difference at all.
At this point I'll ask the community. Have you ever experienced a similar problem? What do you think i could check, too?
Thanks alot.

In my case there's been a reference inside my project which was wrong but that wasn't reported.
I solved my problem with readding all my references even if they were meant as correct.

Check the x:Class property on the pasted UserControl and make sure it matches the fully qualified class name of the codebehind
for instance in you have the following in MyUserControl.xaml.cs:
...
namespace MyApp
{
public partial class MyUserControl: UserControl
{
public MyUserControl()
{
InitializeComponent();
}
}
}
Then make sure the you have x:Class="MyApp.MyUserControl in your MyUserControl.xaml file

Related

Unable to reference a design-time ViewModel in Xaml

I've done this before, but not for some time and clearly I'm missing something.
In short, I've got a design-time model that inherits from my real view model and sets some properties in the constructor.
I'm importing the namespace in Xaml and IntelliSense is suggesting the desired class name, which leads me to believe my naming is error-free.
Even after a clean/build, I'm getting an error saying that the referenced model doesn't exist.
I can refer to the model from a .cs using Aurora.UI.ViewModels.SecurityViewModel_DesignTime without issue.
(In case it matters, this project has a target of x64. This is due to a dependency on an bit-dependent library. It's the only real difference I can point to when comparing to previous implementations).
The name "SecurityViewModel_DesignTime" does not exist in the namespace "clr-namespace:Aurora.UI.ViewModels"
And the model itself:
namespace Aurora.UI.ViewModels {
public class SecurityViewModel_DesignTime : SecurityViewModel {
public SecurityViewModel_DesignTime() {
this.Sensor = new Peripherals.Kinect();
this.PrimaryFeed = Kinect.Feed.Infrared;
Feeds = new List<Kinect.Feed> {Kinect.Feed.Infrared};
this.LookDirections =
Peripherals.Kinect.DirectionsRequired.Front |
Peripherals.Kinect.DirectionsRequired.Left |
Peripherals.Kinect.DirectionsRequired.Right |
Peripherals.Kinect.DirectionsRequired.Top;
}
}
}
(The class it's inheriting from is the 'real' viewModel and is a simple POCO)
What am I missing?
As per the comment, here's an answer:
Do a solution clean, and restart visual studio. Goodness knows why it works. The designer is janky at the best of times.

Class always tries to open in Design View, not Code View

I have a class named Print.cs that always stubbornly opens in Design View, when I need to see its Code View (F7). It also has a different icon to the rest of my classes in the Solution Explorer.
I've looked in the Properties and can't see anything relevant. I've also tried deleting and re-creating the class, but the icon comes back.
How can I force Print.cs to always open in Code View?
(Click to enlarge)
NB: disregard the green squiggly line, it's just a warning that unreachable code was detected.
Taken from the suggestions from #LarsTech and #OrkunBekar, since neither posted this as an answer - this works:
[System.ComponentModel.DesignerCategory("Code")]
Added between the namespace and the class, e.g.
using System;
using System.Collections.Generic;
...
namespace POS
{
[System.ComponentModel.DesignerCategory("Code")]
public class Print : PrintDocument
{
...
}
}
Try right click on the file -> Open With -> CSharp Editor (remember to set it as default).
Funny enough, it was totally other thing in my case.
If the filename equal (=) to the first class in it, then Visual Studio decides it is a simple C# file. If you have 2 classes and the first is not equal to the file name, then the solution icon changes and default editor is designer.
I don't know if you have same conditions in that link but opening your class in notepad, changing codes, replacing file then building the solution again may fix the problem.

iPhone, Monotouch, and XIB outlet issues

I'm having a problem with mapping controls in a subview back to fields on the owning controller. Specifically, I have mapped outlets for each of my "controls" to File's Owner. Monotouch then generated code for the controller's xib designer.cs file to reference these controls as properties on the controller class. However, when I run my code; I get object is null errors when trying to set properties on the controls. Digging into the issue with the debugger; it appears GetNativeField is returning null when trying to access the outlets by their names from the xib file.
Anyone have any ideas why this would be happening? I've checked the .xib file, and the generated code; the Outlet, Property, and Field names are consistent with one another.
Note that the outlets will only be accessible after the view has been loaded and that happens in LoadView() or by accessing the UIViewController's "View" property (this will load the view implicitly).
Only then the the IB content gets constructed and is available for use.
So if you want to change stuff, you would either manually call LoadView(), or override it in your view, call base.LoadView() and then access the outlets.
I figured out what was causing the issue; it was how I was pushing the controller on the stack:
using(var batteryController = new BatteryController()){
navigationController.PushViewController(batteryController,true);
}
It seems that when dispose is called on the controller, the NIB resource is removed from memory; which was causing the issue.
However, this brings up another question. Aren't you supposed to call dispose on the new controller once it's been pushed onto the stack? In objective C, when you push a controller on the stack; your supposed to call release afterwards. So what am I doing wrong then?
you should add the outlets on the AppDelegate. give this a try also on my blog it's a video of a simple calculator, it's in spanish but if you watch it its very self explanatory you can watch it here http://alexsoto.me/calculadora-monotouch it should help you to get started :) hope this helps Good luck, if i can help you on anything else just let me know
Edit: also you can check this video this one uses subviews also should help you, this one its in english http://www.alexyork.net/blog/post/Selecting-a-contact-from-the-Address-Book-with-MonoTouch.aspx

Visual Studio 2008 custom class item template, $safeprojectname$ not reconciling

Just setting up some quick class and object item templates and all is working great so far, but one thing I'm stuck on is the $safeprojectname$ template parameter.
I've added this as part of the namespace portion and the $registeredorganization$ is working fine
namespace $registeredorganization$.$safeprojectname$
{
public class $safeitemname$
{
public $safeitemname$()
{
//default constructor
}
}
}
And I've gone into the .vstemplate file and made sure ReplaceParameters="true" so the only thing I guessed at this point is the period between the company and project name, so I tested this out and just for laughs removed the period, still no go. Anyone have any insight as to why this isn't working?
EDIT: I'll accept Jared's answer as it answers my core question "why isn't it working?" but I am adding this follow up to show how I got my desired result. Instead of using the $safeprojectname$ or $projectname$ I found that using $rootnamespace$
namespace $registeredorganization$.$rootnamespace$
or depending on how your project is named:
namespace $rootnamespace$
works as I had wanted, just added this for anyone else who may come across this issue.
The $safeprojectname$ template replacement macro is only available from the New Project Dialog. It will not work for anything added as in individual item.
Reference: http://msdn.microsoft.com/en-us/library/eehb4faa(VS.80).aspx

Alias and namespace conflict in Visual Studio Designer

I have a namespace conflict between two referenced assemblies:
i.e., I'm referencing Foo.A.Foo and Foo.Bar, so when I say I want Foo.Bar.Control, VS is trying to find Foo.A.Foo.Bar.Control
I can twiddle the Designer.cs code by adding new global:Foo.Bar.Control(), but as soon as I change anything, VS switches back.
I know there's something about adding aliases directly to the reference, I've tried but haven't managed to find the right combination (inline alias, using alias, reference alias).
Help?
"extern alias" may be what you mean, but I'm not sure what the designer will do with it, unfortunately...
I'm not even sure that's what you're after though - that's normally for two types from different assemblies with the same name.
You can write namespace aliases with a using directive, e.g.
using FooControl = Foo.Bar.Control;
but again, the designer is going to rewrite your code...
OK, this isn't the answer, but it's what I found for a workaround:
namespace FooBar
{
class FooBarControlHack : Foo.Bar.Control { }
}
So I can do the following in the Designer.cs :
this.fooBarControl = new FooBar.FoorBarControlHack();

Categories