Can't change Visual Studio adorner z order - wpf

I am writing a Visual Studio extension that hovers above everything inside the text editor (above selections, text, etc).
[Export(typeof(IWpfTextViewCreationListener))]
[ContentType("csharp")]
[TextViewRole(PredefinedTextViewRoles.Interactive)]
internal sealed class MyAdornmentFactory : MyAdornmentFactoryBase, IWpfTextViewCreationListener
{
[Export(typeof(AdornmentLayerDefinition))]
[Name("MyName")]
[Order(After = PredefinedAdornmentLayers.Text, Before = PredefinedAdornmentLayers.Caret)]
[TextViewRole(PredefinedTextViewRoles.Interactive)]
public AdornmentLayerDefinition EditorAdornmentLayer;
// ...
}
Problem is, that my WPF UserControl always "hides" behind the text - no matter how I play with the OrderAttribute.
Am i doing something wrong? is there something else that can influence this behavior?
EDIT: I can now confirm that it ~sometimes~ work, possibly with connection to running without debugging... does anybody know of a related visual studio bug?

It should Work, or better for me is working setting order in your exaclty way.
eg if you start from the template for Highlight 'A' in every line called TextAdornment (comes with vs2010 SDK) and change the zorder from
[Order(After=PredefinedAdornmentLayers.Selection, Before=PredefinedAdornmentLayers.Text)]
to
[Order(After=PredefinedAdornmentLayers.Text, Before=PredefinedAdornmentLayers.Caret)]
the adornments will be placed over the editor Text.
hope it hepls.

Related

Visual Studio breaks Visual Inheritance

I have made a FormBase, from which I inherit a FomBaseList and a FormBaseDetail.
All other forms in the project are derived from FormBaseList or FormBaseDetail.
Now it seems that VS has huge problems with that, and my biggest problem is that VS keeps writing property values from the Ancestor form into the designer.cs from the child form.
for example, in FormBaseList I have this property/value :
this.gttDXGridView1.OptionsView.ShowAutoFilterRow = true;
I expect that in a derived form, for example FormClientList, there is no mention for this value in the designer.cs, because it should fetch the value from its parent. In other words, just plain simple basic OOP.
And I also expect that when I change the property in FormClientList to
this.gttDXGridView1.OptionsView.ShowAutoFilterRow = false;
that this is seen as an override from the baseclass.
However, VS keeps overwriting the property in FormClientList.Designer.cs with the value found in FormBaseList.Designer.cs.
This breaks the rules of OOP in my opinion, other tools that support Visual Inheritance like Delphi for example do this correct.
How can I stop VS from doing this ?
The properties are changed using the designer.
All controls are DevExpress controls, or derived from a DevExpress control.
Another example, which works just opposite so its very strange.
For example put a Button on the BaseForm and give it an image.
The button with the image appears on all derived forms.
Now change the image on the button of the BaseForm.
You would expect the image to change on all derived forms also, but that does not happen.
I discovered that again VS has written the property value of the button in all derived designer.cs files, and this time it does not overwrites them.
I created a ticket about this at the DevExpress forum, and they where able to reproduce it.
It is now passed on to their developers.
https://www.devexpress.com/Support/Center/Question/Details/T692940/devexpress-controls-break-visual-inheritance-in-visual-studio
It also seems I was not the first to report a similar problem.
https://www.devexpress.com/Support/Center/Question/Details/T692244/imageoptions-are-serialized-in-a-successor-when-visual-inheritance-is-in-effect

How to change the default font of the form controls in Visual Studio IDE

I would like to set the default font of the form components from Microsoft Sans Serif to MS Outlook
I can change the font every time I put a new control on the form but its time consuming. I didn't find any help or options for it in the Visual Studio 2012.
How can I change the default font for any added control?
Many Controls you add to a Form, default to some of the Form's properties. That includes the Font of the Form as well as its BackColor. This comes handy if you want to use, say Consolas,10 for all Controls..
Here is MSDN on these 'ambient properties'..:
An ambient property is a property on a control that, if not set, is
retrieved from the parent control. If the control does not have a
parent and the property is not set, the control tries to find the
value of the ambient property through the Site property. If the
control is not sited, the site does not support ambient properties, or
the property is not set on the AmbientProperties object, the Control
uses its own default values. Some objects derived from the Control
class might set the property even if you do not. For example, the Form
class always sets the ForeColor and BackColor properties.
TextBoxes and some other Controls don't get the Backcolor, though.
Note: Changing the Form's font will change those 'inherited' Fonts of all Controls on the Form, including TextBoxes, Lists etc. Those properties you have set directly will not change, though.
So: If you want to use varying Fonts, get the Form's Font right first and try to avoid an uncontrolled mix of default and set values! (You can check which you have set in the From.Designer.cs file..)
I have the same question which bothers me very much, and I can not find the solution for months. Today I finally find a possible solution using my limited concepts on c#.
Back to the topic, just add the 2 lines below in the file "form1.designer.cs", which is in the installation directory of visual studio. My visual studio 2010 have the directory like this :
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplatesCache\CSharp\Windows\1033\WindowsApplication.zip
using System.Drawing; ///this line on top of all
this.Font = new Font("Arial", 16); ///this line in the InitializeComponent()
There are some side effects because some properties rely on the font size, such as the form size will grow because of the Form's AutoScaleMode, default size of button/textbox would be not suitable as you know... But it is not a big issue. A nice programmer could solve this kind of issue by himself.
In this manner you could change anything, such as button/lable font, color... All depend on your imagination.
This is my first post. I hope it helps some guys like me.
The easiest way i found is find and replace feature.
Just double click an item lets say a command button then inside the code hit Ctrl +F to find "font". after you find which default or current font is in use, now broaden the Find to Find and Replace and now replace with your desired font.

WPF Popup permanently displays in Visual Studio design-time

I’ve met strange behaviour for WPF design-time in Visual Studio 2010: after an instance of the Popup class was created, and I switched the code tab in Visual Studio to a different file, the Popup still remains on the screen!
I have a piece of code, which allows to reproduce this, but I am not sure if I should paste it here (it's not so short), so maybe I'll just give a link to it: here.
For unknown reasons beyond mere mortals' comprehension, Microsoft has decided this is the default behavior of the Popup class in WPF. You have to implement the "hiding" logic yourself. I suggest handling the Window.LocationChanged, Window.Activated and Window.Deactivated events of the Window containing the Popup and close it yourself.
Edit: To clarify myself, the Window events you need to handle are the events of the window that contains the Popup's PlacementTarget element. Usually when you create a popup, you set it relative to some element contained in an application's Window (similar to how the tooltips work). If this is your case, then my solution is correct, but I forgot to mention this point about the PlacementTarget.
In your code behind; you can simple check this boolean:
DesignerProperties.GetIsInDesignMode(this);
"this" represent the object containing the popup. For example the Window.
If true you can say:
myPopUp.IsOpen = false;
For Store Apps/WinRT:
Windows.ApplicationModel.DesignMode.DesignModeEnabled

Expression Blend is blocked / locked / malfunctioning?

I am experiencing some very strange behavior with Blend:
Since weeks i am working an a project where I use Blend 4 and Visual Studio 2010 simultaneously. I've never experienced problems with one of these programs or with their co-existence. Work proceeds fine.
But a few minutes ago - from one boot of the computer to the next - Blend seems to have a serious problem:
From now on I am not able alter any value anywhere in my project. I can't create new Controls on a plain surface as well delete existing ones. If i try to alter some attribute of some existing control, the width of an existing button for example nothing happens:
Drag and Drop with the mouse results in nothing more than a slight flickering of the control which looks like if it is fighting against my modification to retain its current value. Regardless what manipulation I apply with the mouse the control stays untouched neither does any value in the properties-panel of Blend change.
It feels as if my project is in read-only mode or locked somehow.
But now comes the frustrating fact: When I apply the modifications described above nothing changes BUT the corresponding XAML code does! Enlarging the width of a button with the mouse doesn't show any effect at the control itself or in the properties pane but the XAML attribute width is changing as I move the mouse ?!
Did anybody also experience this behavior before ? Does anyone has some suggestions ? Maybe the solution is very obvious and just made a fool of myself but I got really stuck with that problem - so any help or suggestions are very much appreciated ... Thanks in advance !
EDIT: It really seems to be a Blend problem because when I open the project in Visual Studio everything is working as it should ...
Are you certain that there is not a control sitting on top of the others?
Alternatively, are your other controls in a panel (perhaps a grid) that has it's visibility set in a trigger? If so, Visual Studio displays controls visibility a little differently than Blend does. Blend attempts to get the property to which you bound your visibility during design time, whereas Visual Studio seems to display the item so long as you have visibility initially set to visible.
Can we see some code to make sure?

Hidden Features of Visual Studio winforms designer [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
One of the most loved and hated feautures of visual studio must be the form designer.
Creating a simple form/user control layout usually is a breeze. Setting properties and adding events is easy.
Setting up the toolbox to use you own controls can be a bit harder and getting the ToolBoxIcons to show up can be a pain. Using third party components by visual inheritance can throw of the designer. And using multiple inheritance on designerables can be really hard.
So what are your favorite 'hidden' and or obvious visual studio designer features.
Hold down CTRL and drag a control to duplicate it.
NOTE: Be careful, if your control has
an event handler that was created by
the designer, it will associate your
newly created control with the event
handler as well as the old control.
Use the keyboard shortcut F7 to go from the designer view to the code view, and Shift-F7 to go from the code view to the designer view. I use this constantly
The "Document Outline" window is essential for heavy designer use. This allows you to reorder the controls in the outline to bring them to the front or send to back. It's especially useful when you're working with docking controls. You can also move a child control to a different parent, or take it out of a container control, or move a parent into a container, etc...
View -> Other Windows -> Document Outline
The "Layout" toolbar is great for lining things up to make a clean looking user interface.
View -> Toolbars -> Layout
When the WinForms project designer is open on a form or user control and you have nested child controls, you can move the focus off of the currently focused child control to its parent control by pressing the Escape key. Pressing the Escape key again moves focus to its parent and so on until you finally reach the top.
Did you know you can actually debug the designer?
You can start up a single solution twice and use 'Attach to process' to debug a devenv environment running your designer controls. This can be especially helpfull to debug 'strange' designer problems that give very little information otherwise.
I used this to pinpoint a designer problem to some remoting that got started and didn't work triggering an unhandled exception and breaking the designer. All I saw at the desigerview was some visual studio internal helper classes crashing.
You can add your own snaplines to UserControls.
The class below here is called CenterSquare, and has a Designer added to it called CenterSquareSnapLines that supplies a list of snaplines inside the control. If you've got your own controls that render smaller then just their borders you can now add your own snaplines.
public class CenterSquareSnapLines : ControlDesigner
{
public override System.Collections.IList SnapLines
{
get
{
ArrayList snapLines = base.SnapLines as ArrayList;
CenterSquare c = this.Control as CenterSquare;
if (c != null)
{
snapLines.Add(new SnapLine(SnapLineType.Left, c.BorderDistance));
snapLines.Add(new SnapLine(SnapLineType.Right, c.Height - c.BorderDistance));
snapLines.Add(new SnapLine(SnapLineType.Top, c.BorderDistance));
snapLines.Add(new SnapLine(SnapLineType.Bottom, c.Width - c.BorderDistance));
snapLines.Add(new SnapLine(SnapLineType.Top, 5));
}
else
{
//Debug message here!
}
return snapLines;
}
}
}
[Designer(typeof(CenterSquareSnapLines))]
public partial class CenterSquare : UserControl
{
//implementation goes here
}
I try to code my own event handler methods when forms initializes instead of letting the designer take care of it. I have noticed that the designer will lose these events from time to time. By coding your own you make sure they stick.
myButton.Click += new System.EventHandler(this.myButtonClick)
All properties on user controls will be shown by the designer and filled with default values for datatype.
Adding the DesignerSerializationVisibility attribute with Hidden as a value will not fill this property with any default values.
<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>
This is a great way to keep the amound of designer code to a minimum. Another option is DefaultValue.
<DefaultValue(somevalue)>
This will set the designer to use the given value as a default value for the selection.
The designer will override backing field values and initializer values if you do not use these attributes.
Another one that can be hard to find:
Menu - View - Tab Order
You can change the tab order by clicking your fields. This option is only visible while the designer is active.
Broken designer:
Sometimes visual studio won't show the switch to Designer/Code option. I haven't nailed down what causes this exactly but mixing vb.net and c# projects while using devexpress seems to be a reason.
As long as visual studio runs it won't suddenly see that my forms/usercontrols can be designed. Closing down visual studio and changing the project file usually helps.
Originally the project file contained
<Compile Include="cboTargetGroupFlights.cs">
Changing that to and reopening the project caused visual studio to recheck all forms/usercontrols and did show the designer again.
<Compile Include="cboTargetGroupFlights.cs">
<SubType>Component</SubType>
</Compile>
Did you know you can set the code view as default after double clicking something in the solution view. Right click you file and choose Open with... and use the Set as Defaults button.

Resources