Avoid Visual Studio to change property - visual-studio

I have a class with various elements and I want to assign a setting to a property, like:
this.MyProccess.StartInfo.FileName = Properties.Settings.Default.MySetting;
The problem is that when closing VisualStudio it auto change the setting to the setting value.
this.MyProccess.StartInfo.FileName = "MySetting Default Value";
How can I make to stay as the first one?

Related

how to call SetExtendedUI on CMFCToolBarFontComboBox

I am creating a MFC application based on example: https://github.com/microsoft/VCSamples/tree/master/VC2010Samples/MFC/Visual%20C%2B%2B%202008%20Feature%20Pack/WordPad
now i want to change the way to expand font name drop list in toolbar from DOWN key to F4. It seems i need to get the combobox and call SetExtenedUI(FALSE) on it, but i dont know where to do it.
To change the extended UI flag on a CComboBox, you call its CComboBox::SetExtendedUI member. When you have a CMFCToolBarFontComboBox you need to get to its combo box first. Since it inherits from CMFCToolBarComboBoxButton you can use its CMFCToolBarComboBoxButton::GetComboBox member to get a CComboBox*.
CMFCToolBarFontComboBox* pFontButton = ...;
CComboBox* pComboBox = pFontButton->GetComboBox();
pComboBox->SetExtendedUI(FALSE);
finally i switched to CComboBoxEx which works fine

Xamarin persist theme

Currently I am only testing on an Android emulator. I have installed the Theme Nuget packages.
In my App constructor I have:
// Load the desired theme (default to Light)
if (Current.Properties.TryGetValue("Theme", out object theme))
Resources = theme as ResourceDictionary;
else
Resources = new LightThemeResources();
I then have a method in the App class:
public async Task SwitchTheme()
{
// Switch the current theme from List to Dark to Light
if (Resources?.GetType() == typeof(DarkThemeResources))
Resources = new LightThemeResources();
else
Resources = new DarkThemeResources();
// Persist the Theme
Current.Properties.Add("Theme", Resources);
await Current.SavePropertiesAsync();
}
When I call the method the theme switches from light-dark-light etc. But when I restart the App, it always defaults to Light. As if the "await Current.SavePropertiesAsync();" did not work.
Can anyone suggest what the problem may be?
Xamarin Forms Properties is intended for use with C# value types and objects that can be easily serialized - not complex objects like Resources.
From the docs
Values saved in the properties dictionary must be primitive types,
such as integers or strings. Attempting to save reference types, or
collections in particular, can fail silently.
All you really need to do is store a string value - either 'light' or 'dark' and then load the appropriate theme based on that. You don't actually need to store the theme itself.

How to programmatically change settings in VS2010 property sheet?

I am looking for a method (macro/plugin/extension) to change values in a specific property sheet (which is loaded into every project in the solution) without having to reload the solution.
Is there a way to access it from a macro or plugin code?
Thanks!
Record a macro when you edit the property sheet and view it's code from the macros IDE. Afterwards you could assign key bindings to it and playback anytime.
This is how I got to work. And you have to add the VCEngine reference with your project.
VCProject project;
Projects projCollection = sol1.Projects;
project = (VCProject)projCollection.Item(1).Object;
VCConfiguration config = project.Configurations.Item("Test Release|Win32");
IVCRulePropertyStorage rule = config.Rules.Item("ConfigurationDirectories") as IVCRulePropertyStorage;
//Setting the Include directories
string rawValue = rule.GetUnevaluatedPropertyValue("IncludePath");
string evaluatedValue = rule.GetEvaluatedPropertyValue("IncludePath");
rule.SetPropertyValue("IncludePath", "Whatever you like to specify here");
//Setting the Executable Directory
rawValue = rule.GetUnevaluatedPropertyValue("ExecutablePath");
rule.SetPropertyValue("ExecutablePath", "Whatever you like to specify here");

Visual Studio 2012 - Variable missing from Locals Window

I have never seen this before and have no idea what it causing it.
When I put a breakpoint at the end of code below, the elapsedSeconds variable is NOT listed in the locals window. If I try to Watch it, the Value = "The name 'elapsedSeconds' does not exist in the current context". How is that possible???
public ActionResult Index()
{
Stopwatch sw = Stopwatch.StartNew();
var userID = WebSecurity.GetUserId(User.Identity.Name);
var model = ModelHelper.GetModel(userID);
long elapsedSeconds = 0;
elapsedSeconds = sw.ElapsedMilliseconds;
return View(model);
}
Select 'Code Optimization' property as "Disabled" in Project property window, in case you want to take a look at the value. It's the compiler optimization process, that renders evaluating that variable unnecessary.
I got this too in a Web project. Neither restarting Visual Studio or any other solution in this thread sovled it.
My solution was to restart IIS. After that I rebuilt the project and started it and got locals to work again.
Rebuilding the solution helped in getting the variable hover feature back.

Name property of UserControl or Control

What is special about the Name property of a Control or UserControl that causes it to be displayed as "(Name)" inside the property grid within Visual Studio?
Check out this article about design-time attributes in .NET. Specifically, I think you are looking for the Browsable attribute, which enables properties in Visual Studio's design-time properties dialogue.
If you have a property called Name, you'd declare it like this:
[Browsable(true)]
public string Name { /*...*/ }
You can set a lot more attributes, like Description, DefaultValue and Category, which will come in handy if you're planning on presenting your controls to other developers.
EDIT: To get the effect that you want, use both the Browsable and ParenthesizePropertyName attributes:
[Browsable(true)]
[ParenthesizePropertyName(true)]
public string Name { /*...*/ }
(Thanks to Ksempac from the comments for this.)
Since you didn't specify if you're using VB or C#, here's the same thing in VB:
<Browsable(true)> _
<ParenthesizePropertyName(true)> _
Public Property Name(Value As String) As String
' ...
End Property
EDIT 2:
I think you're wondering about why you would want to surround your property with parentheses in the first place, or perhaps what it means for a property's name to have parentheses around it.
You can find the answer to that here:
Parenthesized properties are shown at the top of the window — or at the top of their category if the list is grouped by category
Basically, if a property is important, you want it to appear at the top of a sorted list, so you surround it with parentheses to indicate this.

Resources