How to easily change Automatic Property to Full Property? - c#

I have a lot of properties that were originally implemented using automatic properties. Is there an easy way to change automatic properties to fully implemented properties without having to basically delete the properties and start over? In VB, I believe this is possible with a certain combination of cursor position (right in front of the Get?) and a couple of tabs. Is this possible in C#?

In visual studio just type propfull then tab twice, see this link for other good code snippets

Related

Explore object's members like in debug but without debug

Is there any extension for visual studio that can display object's properties / members / methods without debugging the code?
Like it shows in debug when you hover over an object it shows a menu where you can easily navigate between object's members.
I'm looking for extension that can do the same without debug.
If its important the language that I'm working with is C#
Not exactly what you asked for, but you might find the relatively new "peek definitions" in visual studio helpful:
Place the caret / focus on some variable or object, and press Alt + F12.
That will open a sort of internal mini window in VS, showing the contents of the variable.
You can repeat this to step further down in thorough the internals of whatever object you are exploring. Dots at the top of the window show how many levels down you've navigated, and you can click them to move between levels.
In this example I'm at the third level down, as indicated by the blue dot:
This is a great feature for exploring the internals of your class hierarchies without actually opening a bunch of files and cluttering up your main VS window.

Pre-defined XAML code for new control that is added in VS designer

Is there a way to automatically generate XAML code when you drop your control from toolbox to designer? I.e. it would create certain objects (nested properties) automatically and user would not have to type the same code every time to set certain (nested) properties. Kind of a template XAML code that is pre-defined by control's developer.
I'm pretty new to WPF so I'm wondering why there aren't any nested properties in the controls that are in Visual Studio's toolbox (button, label etc...)? Are attached properties a cure for this or have they just cut corners when designing WPF. :)
The problem is that my control (WinForms style property hierarchy) has nested properties and if I "internally" in my code create objects for those properties then XAML does not reflect the situation because it does not have any elements that match the current situation (i.e. the objects created in my control's constructor).
Is the only solution to leave all the properties null and let the user create them all? That way it seems to work correctly but user has to write many lines of XAML to reflect the situation in WinForms.
The functionality that you seek is not available via any of the controls in WPF. However, Visual Studio used to have Macros that would enable us to add pre-written sections of code into our pages, but unfortunately, they decided to remove that great functionality. Fortunately, they have introduced Code Snippets as a partial alternative.
Unfortunately again, these Code Snippets don't work in XAML pages, but once again fortunately, there are a few Visual Studio add ins that will enable you to enter pre-written XAML into your pages at the click of a button on the Code Plex website:
XAML Code Snippets addin for Visual Studio 2010
XAML Snippets for Visual Studio
Please try using one of the above add ins to see if they meet your needs.

Visualize object properties in a WPF control

Is it possible to visualize an object (its properties along with their values) and print it out (dump it - similar to serialization) to a WPF control, such as TreeView or PropertyGrid to inspect the object?
The goal is to display the contents of any arbitary object (not only for debugging purposes).
For further clarification: I'm not looking for any debugging tools or ways to show the WPF Visual Tree. This question has only partially something to do with WPF -> WPF is only the media to display the object dump because controls may vary between WPF and WinForms.
The output should be hierarchical for nested object instances, lists etc.
I think you should take a look at Snoop
http://snoopwpf.codeplex.com/
This program will allow you to navigate the WPF tree of any running application. Debugging is not required for this tool and it's possible the tool doesn't work with debugging. Typically I use it in non-debugging scenarios to see how my WPF controls are actually laid out and what values they have for various properties
I believe what you are looking for is the System.Diagnostics.DebuggerDisplayAttribute
You mean besides the WPF Tree Visualizer? there is Mole, which is not free anymore, but very good.
Edit:
Reading your edited question. You are explicitly naming the PropertyGrid, I take it you've already tried Extended WPF Toolkit's PropertyGrid?
So you want a control that displays at runtime the fields of a class. You will find plenty of articles regarding that by looking for "Property grid". Its not directly what you want but its a start. You basically iterate via reflection over the fields of a class, and display them in a ListView/TreeView. But, and this is were the difficult part starts, determining which fields to show and which to hide, handling with very different types and primitives and allow to edit them with type conversion (like string to Rect, point, color etc) is a very complex matter.
This control might give you a good starting point.
There are various existing controls that lets you view properties as Property Grid.
http://www.codeproject.com/Articles/87715/Native-WPF-4-PropertyGrid
https://wpftoolkit.codeplex.com/wikipage?title=PropertyGrid
https://wpg.codeplex.com/
Based on complexity, License and features they present, you will have to choose one, all of them are free for sure.
I've been searching for the answer to this for months; Snoop, Spy and all the others didn't work for me, due to thread ownership violations.
Microsoft has a windows-tool that allows you to select any running UI Element and view the Element's accessibility data:
inspect.exe
https://msdn.microsoft.com/en-us/library/dd318521(VS.85).aspx
It's available in the windows Software Development Kits which need to be downloaded and installed, and located in:
C:\Program Files\x86\(win-version)\bin\(cpu-architecture)\inspect.exe

How do you view the auto generated designer code for c# controls in Visual Studio?

Right now for my User Controls I right click the control in the Solution Explorer and then choose 'View Code'. Then, in the top right corner where all the class's elements are enumerated in a dropdown box, I choose the grey'd out constructor and this brings me to the auto generated .designer.cs file that I'm looking for.
I feel like this is a really round-about way of doing it and it doesn't sit well with me. Am I supposed to be doing a better job of avoiding editing these files? Are they hard to get to on purpose or did I just clearly miss something simple in Visual Studio?
You should quite simply be able to use the treeview of the Solution Explorer to expand the user control items and see the code-behind and designer files.
This is curious, so I wonder what kind of user control (any particular project type)?
As for avoidance of editing these auto-generated files: yes, you should be weary in doing so, and avoid it wherever possible. Your changes are going to disappear if the code is ever regenerated (not that likely for user controls, I suppose), and the developers of the tool that generated it can't vouch for it working as it should if edited.
There are times when you do want to edit these kinds of files, however. So use your own judgement to evaluate the value of doing so. I find myself dipping into the DBML designer files often enough to delete the default constructor which conflicts with my own in the partial definition, haven't found another way to do what I want. Such is the situation.
Editing autogenerated code is never a good idea. The reason being that the code can be generated at any time and your changes will be lost. If you really, REALLY need to edit the code, you should be doing so using partial classes. But 95% of the time you shouldn't need to edit autogenerated code in the first place. What exactly is it that you're trying to accomplish?
An easy way to do it: Let's say you have a Label control called Label1.
If it is never actually used in your code, place some code that uses it somewhere in one of your methods:
private void Test() {
Label1.Text = null;
}
Now, put your Cursor over the Label1 control and press F12. This will take you to the definition of Label1
Hope that helps!

Why does my class suddenly have a 'designer'?

I just finished adding and removing different database models (I was trying to figure out which one I should be using for this project) then after playing around for a while I noticed one of my classes's icon changed from what is shows beside my Calculations.cs class in the first image to the Balance.cs icon.
The Balance.cs now has this Designer component so when I double click on it I see my second screen shot. This seems to be allowing me to add components from the toolbox to my class. There are actually two classes within my Balance.cs. This Designer thing is only affecting/interacting with one of them (it inherits from SerialPort).
I don't really know what changed or what I did to make this happen and ctrl+z is not being my friend here. How do I change Balance.cs back to a regular class with no designer component?
Thanks
If any of the classes in a source file inherit - either directly or indirectly - from System.ComponentModel.Component (such as SerialPort), Visual Studio will provide design-time support to you. This is sometimes unwanted behaviour, and you can safely ignore it in most cases.
If it really bothers you, you can decorate your class with the [DesignerCategory] attribute (set the category to an empty string).

Categories

Resources