How to: A ListBox from two sources? - wpf

I am using EF with WPF.
How should I create a ListBox that shows both Contacts and Persons?
My question is rather how to retrieve it and create the CollcetionViewSource(s).
I know I will have to use ItemTemplateSelector, that's less what I care, what I really care is the retrieval, but any tips on the representation will be welcommed as well.
Thanks

See the CompositeCollection class.

Related

Listbox or Listview or Gridview?

I am trying to achieve this.
I have a list of records (filenames) which I want to show in a list.
Anybody has any idea as to which control to use.
Regards,
Deepak
The information is right at your fingertips. You should learn to use Snoop. Aside from that, you should choose whatever control works best for you, which requires you to learn the difference between each. We can't really provide a good answer because there are many different ways this control could be implemented, and that's why WPF is so powerful.
Basically, you'll want to use a mixture of a Grid and ItemsControl. You can see the layout of the controls that are being used in this screenshot:

View - ViewModel - Entity Framework 4

I'm looking for a simple way to link a view to a viewmodel and then to Entity Framework through databinding.
Can someout out there give me some pointers. What I'm looking for is a very simple implementation that would allow the view to automatically list all the contents of for example a one field table and for changes in the view to be propogated back to the database through EF.
AAfter spending a long time looking I'm still searching for a way to do this and any help would be very much appreciated.
Thanks,
Technically using a ViewModel means you don't actually bind to your entities. Your ViewModel classes should have everything on them that is needed by the view (and yes, this can cause what feels like duplication, but it's for the greater good), and therefore you don't even have this problem.
You can ease the pain of duplication by implementing something like AutoMapper to avoid the legwork of "left to right" coding where you're just copying properties across.
If you are binding a list, consider having an EmployeeListViewModel that has a property of type IList<EmployeeViewModel> on it, so that you're still not binding your entities directly to the view. This is useful because you can then reuse that EmployeeViewModel for a single-record detail view.

Silverlight ItemsControl wih ColumnHeader

How can I add column headers to a Silerlight ItemsControl? I need a fast way to display a List of items that contains also some header info.
This may seem like a simplistic question but why not use the DataGrid in readonly mode?
The downside with data grid is it doesn't use a virtualised ItemsControl so performance may suffer if you are trying to list hundreds of items with many columns.
There's nothing built into the ItemsControl itself, but there's nothing to stop you from making a custom control that has that kind of functionality. It's a little work up front for the ability to reuse it later if it's a piece of UI you need frequently.
Adding too much functionality to it might be overkill though; if you need column sorting or automatic column/header generation, you may find that a DataGrid (as Anthony pointed out already) would be a faster way of getting a lot of functionality for free.

WPF data-binding manual update

I have a List<Foo> from a non-WPF assembly which I'm attempting to databind to a WPF <ListBox>. Initially, the list items display correctly, but when I add a new item to the List<Foo>, the listbox doesn't add a list item. How do I tell the list box to re-bind / update / refresh the data and show the new item?
Although using an ObservableCollection is the best way, to answer the actual question, the way to update manually is to call BindingExpression.UpdateTarget
You should use a ObservableCollection instead, then you'll get updates automatically.
Thanks for posting this answer. Even if you use ObservableCollection, you may need to use BindingExpression.UpdateTarget. This can be the case if the collection is not in the UI thread. I've been writing some multi-threaded WPF apps, and I've been finding myself having to strip out data binding when I move model code to another thread, because I can't count on the update system to really work. While I find data binding to be a great concept, I think the opaqueness of the data binding system has been a real hindrance for my adoption of it. (Sorry for the rant!) Thanks again, Adam.

MVVM WPF - Usage of Viewmodels

I am having a WPF dataentry form which has got 3 comboboxes which needs to be filled with Master Details like Department, Job Title and Pay Type & other information. All these 3 master information needs to be fetched from the database. I am using LINQ to SQL as my data layer. I have already built the maintenance pages for these master information(i.e. 3 Viewmodels).
Now My Question:
Is it advisable to use these 3 view models for the comboboxes (which defeats the MVVM since there is more than one view model being used for a view) and directly bind them or is it ok if I just use 3 observablecollection of prime classes (Department, JobTitle & PayType).
I would really appreciate any help in this regard. I have lots of form with the same scenario and I am not able to decide on which route to take.
Thanks in advance.
Raja
I think it is fine to use three ObservableCollections in your ViewModel class. This way you can use it as the DataContext of the view itself, which will make setting up the bindings much easier.
As a slight variation on this I might have used ObservableCollections of ViewModels.
This might not might not make sense in your case, but I've been finding it helpful in cases where the combo/list uses a fairly complex datatemplate and the user can interact with elements in the listitem...

Resources