I am using 14.2 for my wpf project. I want to have a window with a xamDataGrid in it and have that window reusable. I have 11 models. The window will show a given models task(which is data that needs maintenance). A model may have between 2 to 7 different data sources(derived from Linq to EntityFramework). The user will choose from a dropdown which table/task to edit in the grid.
Consistent behavior should be as follows:
So I understand I can create field layouts in XAML, however I am wondering if I can do the same thing in the code behind and have the behavior that is required?
Another question is; how do I toggle between the different layouts when I change the data source?
You're very welcome.
Yeah I went through the same logic... just didnt occur to use linq. thanks Rob!
Well, the Fields collection has a Contains method but that expects that you provide a Field object to check against. You probably want to see if a field exists by checking it's name though so that won't work. If you try to use the field name as the index of the Fields collection and the Field doesn't exist, that will produce an exception and we don't want that. So to avoid that you can use a LINQ statement which will return null if it can't find the Field.
Field f1 = e.FieldLayout.Fields.Where(f => f.Name == "MyField").FirstOrDefault();
Just replace "MyField" with the name of the field you are looking for and the result will either be that Field object or null.
Just wanted to be sure I was heading in the right direction. One more question comes to mind for this. How do I check to see if a field exists?
Hi jerovsek,
You have implemented this as I would have expected. Why are you concerned about needing to refresh the grid and what aspect would need to be refreshed? From the sample I can't see anything going wrong that a refresh would fix.