It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have a WinForms application.
In this app I have some Forms and Static class which have a public static property
and some public static methods that need the property to be set because the forms use on
those methods.
Now, if I set this property in the First Form, so when I use some methods on the
Second Form will I get an error or the property is still set (saved the first set on the first form)?
Static variable stay saving its value
What you really want is a Singleton instead of a static class. There is some overlap, but if I understand your desire correctly, the Singleton is the proper approach. See this SO post: for more info and a code listing: Example of Singleton pattern
The property is still set. This is how static properties are actually work.
Static Fields are shared across the App Domain. As a result, the second form will have access to the data set by the first form.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am new to coding GUI stuff, and I was wondering if anyone could tell me whether there is a way to pass objects in xaml to the constructor of another FrameworkElement.
Right now, I am using the code-behind to send an object that does not derive from any of the allowed types in XAML. However, If I were to make the class being passed derive from frameworkElement as well, would it be possible to pass it as an object to a constructor or perhaps set a field to it?
for example
or can properties only be normal value types and is there no way to use constructors beside the default one?
As I said I am currently just passing stuff to the constructor in the C# file that goes with the xaml, but I feel like it would be convenient if it were possible to pass with xaml.
Your doing it wrong.
Unless you are writing a real "user control" There should be very little logic in your view code behind or view constructor. Instead almost all of the logic should be in either View Model or Model types that get into your view through data binding.
This of course isn't always 100% possible, in which case the 'Field' you are looking for is called DataContext. You can set this to an object and then subscribe to the DataContextChanged event and do whatever view specific logic you need there.
see http://msdn.microsoft.com/en-us/magazine/dd419663.aspx among others for more.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
Sometimes I have static types which are really supposed to be static but in rare cases I need to reuse some of their code (couple of methods). I could create an interface or another basic abstract class and solve the problem for several static classes which all really require same methods and members to be overridden but slightly modified. But it still will require me to copy paste large sections of code and I will not be able mark them as static anymore.
You could solve this by building Singleton classes. They can then leverage a base abstract class as well as any necessary inheritance hierarchy, but they still could have static methods that just leverage the private instance if necessary.
Have a look at Jon Skeet's blog on Singleton's so that you build yours properly.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I just thought of a feature for Visual studio that would be so cool, that I'm wondering if it already exists. It would be something like hitting Ctrl+tab when you do an open parenthesis after a method, to automatically fill in the passing arguments with whatever they were called in the method... assuming you named things the same way.
Does that exist?
For example, if I had a method:
public static void Foo(int a, int b)
{
}
And then in another location typed out:
Foo(
I would like to see it populated with:
Foo(a, b)
after pressing some keyboard shortcut.
The similiar feature exists in Resharper. Alt+Enter, then choose Generate argument stubs. But it will fill it with default values like foo.Bar(0, 0);
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm having problems with making the main class static which was not static when the project started. However when I follow instructions to make the class static and run it, it gives errors
This has no errors:
static class MyStaticClass {}
Could you be more specific?
If by 'main' class you mean the one in which you define your main method, then make sure that all members of that class are also static.
This is kinda speculative at this point, but if you make your class static you'll have to make
all its methods static
all its fields static
all its properties static
just about anything about your class has to be static.
In general, you can't do anything that relies on the class being instanciated.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
i want the ability to create a UI designer (Winforms/WPF/UI/User interface type agnostic).
The requirment is that it should be possible to add properties to a device and it should automatically turn up in the UI.The addition of properties would be via a admin screen.
eg. there is a UI object called Order.It should be possible to add a property called ordersoomething to the order object from the admin screen and it should automatically reflect in the User interface.
i am looking for something that is already available (Open Source/existing stuff etc).
Edit based on a couple if comments.
What i mean by UI agnostic is that i am looking for a architectural pattern. That would fit well.it should not matter if it is Webforms or Silverlight or Winforms.
Regards
David Xavier
Since you tagged this C#, make sure you know about VS LightSwitch
There is a DevExpress Application Frameowrk, something called XAF, see the Developer Express website, it's not for free but not too expensive considering what you are asking, I am not sure if it only targets WindowForms...