Need in-IDE update of WPF properties - wpf

I have a real-world problem in which I need to customize the developer experience inside the WPF visual designer and property window of Visual Studio.
I have three properties A B and C:
Each of the three properties must appear in the property window;
Property C must be read-only, and its value must be calculated on the basis of the values of properties A and B, which are read-write; and
If A or B change, the value for C should be updated without having to reload the designer.
How can I achieve this?

Everything related to customizing Visual Studio WPF and Silverlight designers is here.

After checking the documentation and struggling on my own, I have to conclude that what I am trying to do is not possible, since
1) read-only attached dependency properties do not appear in the Visual Studio properties pane to begin with
2) Even if you tried to use DesignModeValueProvider to make an editable property behave like a read-only property, a value that is entered in error will be stored in XAML. This means at runtime you will be setting incorrect values.

Related

Is there a way to name instances in the Property Explorer?

Visual Studio provides a helpful tool window, which allows investigating values of WPF elements in the runtime:
Is there a way to name instances of eg. styles so that I can identify, which specific style got applied to a property of some element?
I'd expect something like System.Windows.Style (name: Abcd)
I tried adding x:Name and x:Uid, but neither worked in the expected way.

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.

Silverlight - Why to Use Attached Property?

I am studying Silverlight (mainly for Windows Phone Development). I read Silverlight 2 Unleashed and currently reading Silverlight 4 unleashed. The latter has a chapter on dependency property. As I got from this chapter is that dependency object (with dependency properties) is used for UI control objects to support animation and data binding systems. Ok. That's clear.
Now, as the chapter goes on, the attached property is discussed. The main reason to use it (as stated in the book as well as on the internet) is to prevent making subclass and add attached properties to the object in concern. And since attached properties are already dependency properties, attached behaviour is added too.
The question now: what do I have to do that? What's wrong with subclassing? and really, why there is alot of code when dealing with attached property?
The question now: what do I have to do that?
Let's look at a great example - layout.
Take the Grid class. If we wanted to support this, every control would need to have a GridRow and GridColumn property. However, attached properties allow us to attach Grid.Row to any control, which in turn allows the Grid to layout that control within itself properly.
Attached properties all work in this basic way - they allow you to "attach" something that defines or helps some behavioral feature work properly without changing the "something" itself.

Strange Overlay Icons Visual Studio

I downloaded a project off codeproject and was messing around with it (I am more an asp.net developer) when I noticed these overlay icons...the lock one on the label is really interesting as when I right click the control is unlocked yet all the properties are grayed out. When I add a new label I do not have that lock icon when I select it. What is this? Also what is the double boxes icon (the other 8 that are highlighted)?
The Winforms designer observes standard .NET accessibility keywords. The Modifiers keyword for a control is what counts here. That sets the access keyword for the member variable. The default for a C# project is private, for a VB.NET project it is Friend. VB.NET is more friendly about it.
That matters when you derive a form from a base form, Project + Add New Item, Windows Forms node, Inherited Form item template. The derived form will have the controls of the base form but they cannot be changed if their Modifiers property is Private. The designer makes it obvious by displaying the lock icon. And by displaying the properties of the control in gray text.
Normally this means that the controls are defined in the base control and so you cannot change them in the derived control (so they are all locked).

Resources