Thursday, 15 September 2011

c# - Dynamically adding a new way to display collection information in WPF -



c# - Dynamically adding a new way to display collection information in WPF -

i learning wpf bear me.

i have viewmodel observable collection of (very simplified here brevity) employee objects looks this:

public class employee { public string name { get; set; } public string title { get; set; } }

in c# wpf application, displaying info observable collection in tab command in view via simple info binding. easy stuff far. requirement user can dynamically add together new tab displays info employee interested in , new view of employee info saved , re-loaded each time application run.

so, let's user wants new tab added displays employees software engineers. need give them method take filter criteria , add together new tab tab command shows employees match selected filter criteria. custom view of employee info in newly created tab should saved , recreated each time application run.

i don't need total code examples, although helpful. suggestion approach can go google information. not sure techniques best solve problem. thinking dynamically created datatemplates or custom collectionviewsource, need info saved , reloaded save dynamically created datatemplate , utilize when application loaded?

from understand, tabs each have filter , observable collection loaded based on filter.

if case, 1 possible solution define view model represent tab (employeesviewmodel). view model have properties filter , observable collection plus other methods save / modify observable collection.

public class employeesviewmodel { public filter filter { get; set;} public observablecollection<employee> employees { get; set;} public employee selectedemployee { get; set;} public routedcommand saveselectedemployee { get; set;} … }

once have this, create class serializable (by implementing iserializable). should serialize filter conditions, not content of collection.

when shut downwards application or when teardown tab viewer module, iterate through tab collection, associated view model , serialize each of them. , when start application (or tab viewer module) recreate each tab using deserialized view model

c# wpf

No comments:

Post a Comment