I have this project I like to use WPF ListView
it will look like a PropertyGrid in Winform. I already found some implementation on the web, which is the best?
from what I learn, I can only binding a class from DependencyObject, is it possible to binding a generic List or Dictionary, myClass will include name, value, type (string, double, bool, lookup list, ...). Once I binding it, it w开发者_如何学运维ill add relate template, e.g. for lookup list, it will add combobox in celltemplate.
further, I like to have everything in a configuration file. e.g. I have this configuration:
Name1, Value1, string Name2, Value2, bool Name3, Value3, lookup, N3_option1, N3_option2, N3_option3, ...
my code will read configuration file first, then from there, I read Name1/Name2/Name3 from database, show them in my ListView, from Name3, you pick value from (N3_option1, N3_option2, N3_option3, ...).
If you can point me the right direction, I will appreciate it so much.
Update: here is 3 examples I'm looking at:
DataTemplates in Action: Building a simple PropertyGrid, WPF PropertyGrid - MVVM techniques, and WPF Property Grid.
"WPF Property Grid" is too complicate for a beginner like me. Personally, I more like "DataTemplates in Action: Building a simple PropertyGrid".
it also have code to select DataTemplate depend on DataType of each class property: bool use BooleanDataTemplate which is a checkbox; Enum use EnumDataTemplate which is a combobox.
I also like go a little further, add custom type: lookup, which will show as dropdown list, but the value list come from database. e.g.
property name: car manufacturere, value come from "SELECT LOOKUP_VALUE FROM LOOKUP WHERE LOOKUP_KEY = 'CAR_MFG'", which will return a list like: Toyota, Ford, Nissan, Honda, VW, BMW, ...
If I have > 1 lookup properties, how I can speciafy them? LookupDataTemplate1, LookupDataTemplate2, ..., then how to specify them in XAML Resources. and all DataTemplate are pre-defined in XAML, how I can do it in this case.
similar to EnumToListConverter, How I can create LookupmToListConverter1, LookupmToListConverter2?
1) I am unsure what the question here is. You can do it with a ListView, its just a matter if it fits your data well. It sounds reasonable given what you wrote.
2) You can make a DependencyProperty
that is a List or Dictionary and bind to it that way. You can also use the ObservableCollection<T>
class (basically a list that notifies when its state changes) and bind to it. You can also use any other class that uses INotifyPropertyChanged
and bind to that. Adding the combobox through the template sounds appropriate.
3)It sounds like you you need a class to use to read from your configuration and then display it to the list view. These would be your view model. You could make a class that implements INotifyPropertyChanged
for this. You'd have three fields 1)Name 2) Value, 3)Potential Values. Name and value both would be strings. I'm assuming Name would be a one way binding and Value would be on a two way binding on the combobox whose items are bound to the Potential Values. You then would create an ObservableCollection<T>
of these objects and bind your ListView
to that. The serializing and deserialzing to this collection should be relatively straightforward.
精彩评论