applying images to a dynamic data listbox in xaml - wpf

I'm new to xaml and wpf. I actually wanted to create a dynamic listbox populating a list of customers with images ('redball' for old customers and 'greenball' for new customers) adjacent to the names in the list. The list as I mentioned will be having random number of entries. Kindly suggest me or guide me trough any samples or blogs which might be helpful.
Thanks

if your customer object has a public property (IsNew or something like that) then you can simply use a datatemplate with Style.Datatrigger to show a green or red ball. if you a new to wpf you should read some books to bwecome familiar with bindings, xaml styles and so on. and if you did this you should read about mvvm pattern.

Related

WPF / MVVM: Show specific image from list of images?

I have two lists of different object types in my ViewModel. For example I'd say the first one is a list of all available images, the second one is a list of all articles. Each article belongs to an article category for which I'd like to show a thumbnail in the GUI when an article is selected and shown. For the sake of a simple example I assume that the Id of the category equals the Id of the corresponding image.
For a ComboBox this would be an easy task: I would assing the list of all images as ItemSource and then the article's category key to the SelectedValue. The SelectedValuePath would have to point to the Id of the image.
However a ComboBox does not make sense here as I only want to display the correct category image - I do not want any editing, a dropdown, etc... How would I solve this with a regular Image-UserControl (or maybe a similar UserContro)?
BTW: Right now I have to use an additional Property on my Article class which directly holds the correct image, but I think there should be a better way to solve this issue.
Any ideas?
Regards
ralf
There's no problem with creating a get-only property on your ViewModel that provides the image that the view should bind to. The whole point of ViewModels is to shape model data into a structure suitable for binding views to.

Dynamic Databinding in WPF

I am filling up a Stackpanel with Textboxes. Each textbox, Should display the Value Property of a Class i have written.
The number of Textboxes is always different so i can't create a databinding in the xaml file.
Are there tutorials, that show how can i archive my goal?
Edit: Thanks for the replies so far. After reading the articles i still not clear how to implement my Problem.
Here is what I'm trying to achieve:
I have an SQL Server DB and there a Table with an ID and a Value.
I now load all Values and IDs i want to display into my application. (number of loaded rows is always differnt).
I need to display a textbox for each row and display the value there and after the value is changed i write the value back to the database.
I don't know how I should query the data and than bind it to the textboxes.
I don't need an implementations, I am happy with every piece of advice I can get.
yes there are a number of tutorials out there. It sound like you are interested in datatemplating.
I would suggest looking Here on MSDN. A few tutorials on databinding in general may be useful DataBinding on MSDN
If your class, classValue, has a public property Value then just create a List and bind that to a ListBox with the item DisplayValuePath = Value. Repeater controls are used to bind to collections.

Paging a Listbox control in WPF

I have a WPF ListBox with it's ItemSource property bound to an ObservableCollection. Each ListBox Item has many controls that could take some time to load up.
I would like to only display/load 5 ListBox items at a time, with some paging support or a "Next" button or something similar.
Currently I plan to do this manually and just keep two different collections. One would be the master collection with all the objects, and other would be the ListBox's collection where i would just remove 5, and put in a new 5 objects. I was just curious if there is something built in that would make my job a bit easier in this situation, i'm very new to WPF and all the binding techniques, and I have a habit of doing everything the old fashion and manual way, but I'd like to start using some of the newer 'quicker' techniques.
Thanks
just look into Bag of Tricks by Kevin
https://github.com/thinkpixellab/bot
you can see the page list viewer.... in the examples...

How to use two templates for ListViewItem using WPF

I would like to have a ListView that would have have items similar to Microsoft Outlook inbox with items arranged by Conversations (see the attached photo). An item can either be a simple textblock containing the topic of the conversation (on the photo this are the blue lines) or it can contain email information specified by the ListView's header. It would be best if the items with conversation topics would be push buttons so that emails inside that conversation could be shown or hidden by pressing this button.
Any ideas how can I achieve this? Do I specify two ListViewItem templates? If yes, how do I tell in the code which template to use for each item?
Any help will be GREATLY appreciated!!
Regards,
Gregor
alt text http://img401.yfrog.com/img401/1719/inboxy.png
You should check out DataTemplateSelector. just google it.
The idea is this.
You will define 2-3 templates in XAML
create a class derived from DataTemplateSelector and based on a field/ typeof object
you will return the appropriate template
The concept used in your screenshot is called Grouping. You can easily use grouping if you have a ListCollectionView as your ItemsSource. You then need to specify several GroupDescriptions for the ListCollectionView's GroupDescriptions property.
To define how these groups look like, you might have a look at this SO post: How do I group items in a WPF ListView. Other blog posts of interest might be: Bea Stollnitz: How can I do custom Grouping?, and Bea Stollnitz: How do I sort groups of data items?
In your scenario you would use the title of your email conversation as the group header, and maybe some additional data.

How to set up Header/Lines in WPF/Silverlight

Do you have any best practices for setting up Header/Lines forms (Also known as Header/Details) in WPF or Silverlight? Preferably using the Mode-View-ViewModel design Pattern to fit in with the rest of my application.
An example would be if I had a grid that displayed all SalesOrders in the database, and the underneath that a grid that showed all of the SalesOrderDetails (The individual lines for the sales order...each item sold) for the selected sales order in the top grid.
I realize I could do this in the code behind file on the Grid's SelectionChanged event, but I'd prefer a declarative way of doing so...in all XAML and ViewModel code. Is this possible?
Thanks,
Roy
Header/Lines sounds a lot like the Master - Detail pattern to me. To implement something like this using MVVM is quite simple.
If we were to create a structure where we had a MasterViewModel and a DetailViewModel then in our MasterViewModel we would simply need a property to represent our list of Details and the current Detail. In the View we can bind a list's ItemSource to the collection of Details and bind the SelectedItem to the CurrentDetail property. We can then have a seperate View, as a DataTemplate or UserControl, that represents the CurrentDetail and displays our values in the detail grid.
There's also some good resources out there on implementing a Master Detail pattern XAML.
Bea Stollnitz has two excelent samples using XML for the Data Sources: Here and Here.
There's a MSDN video on implementing the pattern in WPF. (The video is in VB but the code can be downloaded in C#).
In this MSDN forums discussion Johnny Q. demonstrates a simple Master-Detail settup using MVVM.
A lot of Karl Shifflett's examples also end up demonstrating the Master-Detail pattern, though the code is usually in VB (however some examples come with both C# and VB code.)

Resources