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.
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 have searched a lot for this and found a bunch of things that might help, but i a, cannot implement them in my code, and b, its not exactly what i need for my code.
Essentially, i am looking to have an inventory update web form. When you get to the page, there is one drop down list, and based on which item you select (add inventory, remove inventory) different options appear on the page.
That being said, im trying to dynamically create different fields based on the autopostback dropdown list, and i have the fields appearing fine. However, i cannot get any values that i need.
For example, whenever i try to set
theText = textBox1.Text
it comes up null.
would this be easier with java script or am i just missing something?
thanks
Though your questions is extremely vague because nobody knows what your code looks like or where it is, when dealing with dynamically created controls there are two guidelines to keep in mind:
All controls should be created and added to the page in the Page_Load so that the events and properties can be set via ViewState.
When accessing properties, they need to be accessed outside of the Page_Load because the values would not yet be available as they have not been bound. You would need to grab these values in an event like PreRender.
If you know the ID of the dynamic control you can find it with Page.FindControl():
http://msdn.microsoft.com/en-us/library/31hxzsdw.aspx
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.
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.
This question has been edited to ask about a specific example as the original question was deemed unanswerable.
Given an application that needs to display information about various objects (including similar and inherited objects) would it be better to pass in base class objects to the display function and allow it to query the object to determine what data to display; or should you just pass in each of the fields by value. The advantage of passing by value being do not need a direct dependency on the objects they representing, thus keeping the display (UI) isolated from the business rule objects.
In general, you should pass the minimum amount of information that a method needs to do its job. For example, if a method is computing a person's age given their birth date, you don't need to pass in the entire Person object, you just need the person's birth date and the current date.
By following the above approach, you keep your methods loosely coupled, which makes them much more maintainable.
In your case, you have to balance whether you need to access a lot of fields of the base classes in these methods, or if you are just need to access a few. If it's a lot of fields, then it may make more sense to just pass the entire object. It's sort of a balancing act between having good coupling (see first part of this answer), but at the same time, avoiding passing tons of parameters to a method.
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...
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.
HI ,
I am currently trying to learn more about custom controls and how to use them etc. i have come across iTemplate interface and was hoping that someone could better explain its use and point me toward a good example implementation. From what i have found it allows you to change how an asp.net control will display items. ive tried searching code project etc for a good example but none explain it well. Id ideally like a very basic example and a more complex one.
thanks
Niall
ITemplate: Defines the behavior for populating a templated ASP.NET server control with child controls. The child controls represent the inline templates defined on the page. (taken from MSDN).
Take a look at these great tutorials: Developing Custom ASP.NET Server Controls or Templated Server Control Example.