I wish I could understand how the loading of xaml files into rehosted designer works. Depends of xaml definition I get different results.
Xaml, root node in the file is Activity that cointans flowchart. Here it's enough using desinger.Load(xamlFileName) with (new DesignerMetadata).Register() after creating the designer (anyone know what kind of magic is that?) In the designer I get workflow that looks like in visual studio editor.
Xaml, root node is Flowchart itself. The same steps give me only one, bare activity in the designer. I tried wrapping workflow in activity builder according to this(I have a similar problem). There are no problems with assemblies(at least I think so), no exceptions. I can't make it work like in previous point.
Is there any difference between xaml saved in visual studio and xaml saved in rehosted designer?
ActivityXamlServices.Load sometimes returns DynamicActivity, sometimes the target workflow. What does it depend on?
Thank you for any support.
Turns out that it depends on the argument given to the rehosted designer. If I start with new Flowchart, the root node in xaml will be flowchart. When loading such file later to the designer you dont need to wrap it. If you started with ActivityBuilder you might need to use WorkflowInspectionServices to get the workflow before loading xaml.
Sometimes to show workflow properly in the designer you need to use (new DesignerMetadata).Register() from proper assembly, but its not always necessary, I'm not sure what does it depend on.
Related
I'm experimenting with language support extensions in Visual Studio. The MEF support seems pretty straightforward for the most part--I've got working file type and project file support, syntax highlighting, etc--but the part I can't figure out is the form designer. Somewhere in Visual Studio, there is a mechanism that says "this file uses the form designer and this file doesn't", but for the life of me I can't find any documentation anywhere on how that works, and the stuff I do find that touches on designer support, like this MSDN page, turns out to be a big useless ruaround.
Specifically, I need to know two things:
How to tell VS which particular files are supposed to open with the WinForms form designer? (I'll get around to WPF eventually.)
How to tell VS that the form designer should work exactly the same way as the standard C# form designer, except that it should use this custom CodeDOM parser for serialization and deserialization to and from the target language?
Maybe I'm just looking in the wrong place, but I can't find (useful) documentation or code samples for this anywhere. Does anyone know how to do this?
After several days of happily hacking away on this C# app using Visual Studio 2008, I get struck by a barrage of error dialogs showing:
Code generation for property 'valueMember' failed.
Error was: 'Object reference not set to an instance of an object.'
This happens now often when I make a tiny change in the designer, e.g. shift a control a few pixels, and then try to save. Several such error dialogs appear each second, keeping me busy cancelling all those by hammering the Enter key while trying to get alt-F4 to get VS to close.
Eventually I do get VS to close and to save the changes I made. After restarting VS, I do "clean" on the entire project, then "build" and everything works fine, the app runs fine, no problems.
Until I make another slight change in the form designer.
I don't know about any property valueMember in my app.
This makes me crazy, it is a real showstopper for my project. Any help is appreciated.
Try to Close and reopen the Visual Studio. maybe it seem silly, but it works!!
You can debug the designer using another visual studio and attach to process. If you got exception it should be easy to find it that way.
In general when openning the designer the constructor and of course initializeComponent is running.
As this is happening at design time, it is likely that you have a custom control which requires a parameter or other value which does not have a default.
When in design view in Visual Studio; a control instance is created to render it on the visual editor, but if the control requires a property to be set before it can be rendered, it will result in an error.
Can you check that all custom controls have default values, and anything referenced in the constructor that cannot have a default is wrapped by DesignMode property - see http://msdn.microsoft.com/en-us/library/system.componentmodel.component.designmode.aspx.
Similiar to #Chanipoz's answer (close/re-open) my component-rich/user-controls-everywhere forms app started to compile happily after I closed down the main form designer window.
I've had this code stack for years and have never seen the error until today. Not sure where it's coming from. But, something today about having the form open in the designer made everything unhappy. Simply closing it off of the screen made it all go smooth.
Use another instance of Visual Studio to attach to the first instance of visual studio.
Go to Debug-> Attach To Process and look for the devenv.exe process. Since you'll have two devenv.exe processes running you'll probably want to pick the one with the lower ID, that's usually the first instance of visual studio that was run.
I had to face this problem. As I have found the solution below
I am facing this issue in my customized control.
we need to implement like this
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public MyCustomclass _Prperty { get; set; }
I had to face this problem. As I have not found the solution (much inheritance), I can tell:
.SuspendLayout() and .ResumeLayout() may be missing in code or one of them. The same is with .BeginInit() and .EndInit(). It is expected between them, that there will be = new ... and some settings for properties. Maybe someone facing this problem would find the solution with this information.
The problem is missing initialization code for a public property on the control. This will be added for you when you add the control to the designer, but if you replace a control with a derived control, or update the component, then the designer does not know how to deal with this.
If you have a control (wincontrol) with a public property PropertyA, and you add it to a form (myForm), then the designer will add all the necessary initialization for properties into myForm.Designer.cs. Something like;
Wincontrol1.PropertyA = new List<widget>();
It is not uncommon to need to modify a control slightly, lets say we have a new control MyWinControl
public partial class MyWinControl : WinControl
{
public List<wodget> PropertyDer1;
protected List<wodget> PropertyDer2;
}
If you sub this new control for the old control in myForm.Designer.cs, then you may well encounter this issue. The reason is that PropertyDer1 has no initialization in the winforms designer. PropertyDer2 won't cause any issues because it is protected. Similarly if you had a custom component and you add a new public property after the component has been added to a form.
If however, you deleted the instance of WinControl on the form, and dragged an instance of the MyWinControl onto the form instead, the proper initialization would occur and you would not see the error. The designer will have created the new control like this
Wincontrol1.PropertyA = new List<widget>();
Wincontrol1.PropertyDer1= new List<wodget>();
There are two easy solutions that do not require hiding the property from the designer.
1. If the property doesn't need to be public, give it the right modifier
2. If the property does need to be public, then just edit the code in the myForm.Designer.cs as in the code above to add the missing initializer
If could be of help I just detected a case that brings that same error message, impossible to take away :
I am developing an application in French, and I had to create a ToolStripMenuItem with an accented word in it like "annulées".
The system generated a menu item like "annuléesToolStripMenuItem" and the accent is the culprit.
Enough to delete the item, create it again in English and the just change the Text property of the menu item.
Hope it will be of some help.
I have a winforms application that I am writing in C# - in Visual Studio 2010. I have one specific form that keeps corrupting itself every other day or so - according to TFS, it looks like most of the file is re-written by the designer when I have made only the smallest changes. (location of buttions, etc.) Things fall off strips, toolbars, etc. as well as errors just trying to use the designer. See my other post Here. (Thought I figured this out, but I guess not)
Here is an example piece of code that goes missing - when I put it back in, it takes it back out when I save the file. The code was generated by the designer in a previous file version.
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.tssEmployeeName,
this.tssLoadTime,
this.tssSpring,
this.tssHomeLocation,
this.tssTotal,
this.tssDue});
Is there any way of 're-generating' the [file].Designer.cs file? Or should I bite the bullet and re-do this form? (pain with over 100 components on this one...) It's the only form I have a problem with out of the 35 or so in the project.
VS 2010 w\ SP1.
Thanks, Andrew
I've experienced this before, although I'm not sure if my issues were exactly the same.
Try putting a handful of problem controls, such as your StatusStrip control and its children, into separate User Controls. Then add those User Controls to the main form instead. At the very least, you can prevent the designer from rewriting those controls.
I have been wondering from the first day, when I started to read, how does the .NET Framework work?
First it's really good to have an IDE like Visual Studio. While for example when I click and drop the textboxes, buttons, set their properties and so on, everything works fine.
But in the case of Java in most cases we as a programmers write coding to develop a Frame (window). But in case of .NET, Visual Studio make things easier, but how does work that, without writing a single line of code, all Windows, buttons, etc. are created?
And if I change the button name in the Form design area, where does this get stored, and more importantly how does it get displayed when we execute our program? Is this magic? Or there is a long process under the hood?
There is absolutely no magic behind this. The visual forms designer in Visual Studio generates C# code for you. Just chceck the Form1.designer.cs file.
The code in your .designer.cs is generated by serialization (objects -> code, code -> objects). Look at the CodeDomSerializer class if you wanna try understand better what is happening under the hood (with Reflector you might wanna check ControlCodeDomSerializer in System.Design.dll). And of course you can create your own serializer for custom controls and components.
This is a general question, but I'll explain my specific need at the moment:
I want to find the framework class that enables one to choose an image at design-time. I can find the editor that is used at run-time - its the Drawing.Design.ImageEditor. At design time, however, a different editor pops up which allows one to choose an image from resources.
I'm guessing I could run some kind of program, then open up the image editor, from the property grid, and see what new windows/classes have been created?
Thanks
Yes, you can see what's being used by using another instance of Visual Studio and use Tools + Attach to Process (managed) to look at the call stack. It is a Microsoft.VisualStudio.Windows.Forms.ResourcePickerDialog. That is not something you can use in your own code, the Visual Studio designer assemblies are not re-distributable. Nor would they be useful, they monkey with the design-time state of the project.
Making you own isn't that hard, just use Reflection to iterate the properties of Properties.Resources and find the ones that have the Bitmap or Icon type. Display them in a ListView to allow the user to pick one. Adding resources at runtime isn't an option.
A tool with similar functionality to what you mention is Spy++ which you can find in your Visual Studio folder on the start menu (under the sub menu Visual Studio Tools).
However, if I understand you correctly, I don't think the design time editor you're talking about is written in managed code and even if it was, I'm fairly sure it's not in the framework. It's just part of Visual Studio itself and as far as I know you can't get hold of the source code for that.