Silverlight WPF Generic Data Item - wpf

Basically I use lists to display information, these lists contain custom data items I have created, they all look similar and have some of the same controls in them, essentially they need to look the same colour, font etc. At the moment, I just seem to be repeating code over and over each time a change is needed i.e. colour.
I have been wondering if it would be a good idea to create a generic data item which all the lists use and then just collapse controls which aren't needed.
So I was going to create a user control called something like "GenericDataItem". This data item will contain all the controls that each data item would need, then use dependency properties to collapse controls not required.
My question is would this be the right way to go about this, or is there a better way?
Thanks.

Not sure I got the point, but using DataTemplateSelector could help you.

Related

Nested ListView Items - TreeView&ListView combined

The best way to show what I need is showing an image:
What is the easiest way to implement this kind of "nested ListView" - each Item can be expanded and has subitems. I want the hierarchy only to show on the first column as shown when any other solution can be accepted.
There are couple of ways to do it. I consider that you are good in WPF and easily check code and take idea from it because it is not easy to give code of your requirement here.
You must need to user Expander for expand and collapse functionality for the detail sections as per you image.
I am sharing some the links from where you can easily get what you want. It is not exact code which you can copy but it will give you basic structure of what you want.
Listview and Expander
Sample-1
Expander and DataGrid
Sample-1
Sample-2
You will enjoy working on this one.

best way to implementation this UI?

one button with wrapped list view
my searched result are:
1.worst approach: put add button on the wrapped list view.
2.bad approach: set two data template for list view.
3.?
thanks
I've had something similar a while back. In the end I decided to add a fake data item where I needed the button.
Say I had a list of MyDataItem, I created a derived class MyFakeDataItem and added that at the end of the list, after I finished populating it. In the WPF I created two data templates, one for each class, and a selected to decide.
I think it turned out quite elegant, since it allowed me to easily override any real functionality I had on MyDataItem, and add a command on the fake one to suit my needs.
Hope that helps.

When to use custom user controls

I've got a massive UI that I'm designing. The way that my employer wants it, there are at least 100 labels. Now, I've always thought that in cases like this, breaking up the UI into smaller custom controls was the ideal way to go. However, someone recently told me that custom controls are really only for code re-use. What is the actual suggested practice for this?
EDIT
The finished form will look like this:
Now, I'm using WPF for the UI, and I'm thinking of breaking this down into smaller bits.
Based on your image i see some repetitions, each of this repetitions could be a custom UserControl
But it depends on the usability is it easier to write a custom UserControl so do it but if it would reduce the readability of your code and it also adds additional complexity don't do it
here are an example of what could be separate UserControl's
the green ones are possible useful encapsulations of logic
the orange ones maybe need some not market stuff (don't know enough about your software)
the red ones are the maybe's based on the intern use (from the visual part they are repetitions so the should custom UserControl)
Since your UI is read-only, I'd suggest using a grid.
Are you new to WPF? To break the View into bits WPF offers you CustomControls and UserControls. They are two very similar things yet completely different from each other. CustomControls are Buttons, Labels, TextBoxes, DataGrids...etc. They are basically simple stand-alone controls. UserControls are groups of stand-alone controls serving a purpose such as example a Button and a ComboBox next to each other so user can select something in ComboBox and confirm that by clicking the Button.
If you wish to display data from database I suggest you DataGrid which will give you a table-alike look with rows and columns and all that. If you wish to place few buttons next to DataGrid on which the user may click to insert a new row or to edit a certain cell then I suggest you to wrap all that with a UserControl which you can reuse in other places where you have to display and change data from database too.
You should be using a datagrid and can customize its template to render individual cells as Textblock (lighter version of Label) from a rendering perspective. The main difference between Textblock and Label is very minor things such as access keys and disabled state behavior. But from a WPF object hierarchy - Textblocks are much lighter. But besides that point - from your employer perspective - once you have customized the grid template and render them (so as they look as textblocks/labels) - your employer should have no problems.
Also as somebody suggested above - if you want to logically break sections of the UI since they maybe coming from a different table in db - then User controls is the way to go (for maintainability of code)
Let me know if you are looking for more technical details or need help further technically.
There is nothing wrong in making and using custom controls or user controls or defining some data templates which will be reused depending on how your data is organized.
For sure the UI looks pretty messy and some sort of grid should be used with templates for example where there is similar data. I also have the suggestion and first think about the data and the functionality before starting and let the UI be driven by that. For sure you will the reuse controls/templates. If you think in front on the model and behavior the UI can afterwards more easily changed.
Create your viewmodel correctly, implement the functionality in commands, use bindings, after that the UI will come naturally, reuse controls, use several grids, make the UI more user friendly using several regions, tabs, windows or anything that makes the user more comfortable.

What is this widget called in GTK?

I was wondering that currently we have gtk.TextViewWidget to display the contents of widget. I was wondering is there any way to make a type of My Computer Properties dialog box where there are different panels at top and one can click on any one of them to display the contents of that property.
Can anyone give me some good advice on how to proceed making this?
Sounds like you need a GtkNotebook.
I'm not sure I understand fully what you mean, but it sounds as if you could easily just stack a GtkTreeView on top of a GtkTextView to achieve what you want. Populate the tree view with a suitable model holding the items in your computer (how to find this information is of course a separate problem), and then as a tree item is clicked, modify the text view's buffer to display the associated information.

WinForms - How do I create a table using a custom control for each row?

I want to create a table representing data I have, but I want each row to have a custom display. I have developed a little custom control that represents a row and has a few items in it (text box, check box, progress bar), however how do I now in the main form create multiple instances of this for the data I have?
e.g. is there a winforms control I can use to do this? or do I have to take a panel or something and programmatically do it?
I do need to somehow take responses back. So if someone clicks on the button in the 4th row say then I'll need to be able to tell which row it was from.
As an aside would then be a way to BIND the above mentioned visualization of my data to the data itself, say housed in an Array?
thanks
I see two options here:
You can use a DataRepeater. This control can be found in the Microsoft Visual Basic Powerpack. It allows you to place controls on a template which gets copied for each item in the databound collection.
You can create a custom control and manually place one instance of it for each item in a collection, re-creating databinding for the controls in it. This requires you to either expose the controls inside publicly or as properties of the user control.
However, above options are mostly useful for non-tabular data. If your layout is strictly tabular (i. e. rectangular cells in a grid) then you can create a custom DataGridViewCell which takes some time to understand but not too much code. Putting a progress bar into such a cell shouldn't prove too difficult.

Resources