Hi,
Hope you can help me.
My XamDataGrid settings are:
<igDP:FieldSettings AllowRecordFiltering="False" AllowEdit="False" Width="Auto" AutoSizeScope="AllRecords" />
<igDP:FieldLayoutSettings AutoGenerateFields="False" AllowAddNew="false" AutoFitMode="Default" />
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout>
<igDP:UnboundField Name="ItemUser.Name" BindingPath="ItemUser.Name" Label="Usr" />
<igDP:Field Name="Description" Label="Description" />
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
If I change the UnboundField to Field, it doesn't work and hide all.
I'm sure the properties are there.
Could be the AutoGenerateFields="False" ?
How can I show a property of the object using Field like ItemUser.Name ?
Any ideas?
Many thanks !!
The most frustrating thing about XamDataGrids is that if one of your fields is incorrectly configured, the whole grid will be blank.
Your grid's DataContext should be something that's a container of ItemUsers (like a List<ItemUser> or BindingList<ItemUser>). (In xaml, set a Name="foo" for your igDP:XamDataGrid, and in code-behind, set foo.DataSource=<your container>.)
Once you have that, this should be the minimum that is necessary:
<igDP:Field Name="Name"/>
If ItemUser has a public field "Name", you should see it in your grid, and the column header will be "Name". You can use Label to change the column header, and DataType to change the displayed data type (e.g. make an int property display like a double, for instance).
I suggest adding one field at a time, since one mistake will cause your entire grid to go blank, and it sucks to track it down after you've added 12 fields.
Thanks gbirchmeier,
The Object structure here is really simple:
Class Item, has a Description(String) and one ItemUser(User). User has a Name.
Why I can't write in a Field ItemUser.Name when I have a Collection of Item as data source of the XamDataGrid ?
Any idea?
Thanks a lot,
Thanks, I have checked out that sample.
From what I can tell, it is using Field with simple bindings, not UnboundField with complex bindings. Also, it seems to be focused on demonstrating how to detect changed values, using the DataValueChanged events. This isn't a problem for me - my ViewModel is already detecting it's own data changed events, so I already have flags in the ViewModel to represent those concepts, which hopefully the GUI can bind directly to somehow. So I'm not really looking for a solution to explain how to capture data changed events, as I'm already doing that. I also really don't want any solution with code-behind - I am trying to build a pure MVVM solution here.
So what would be useful as a starting point would be a similar example, but with UnboundField instead of Field - it seems these have different data structures, and so the code doesn't translate over directly.
Specifically my questions are:
1. What is the best target to provide a style on, in order to capture the fact that my cell's bound value (and some of it's child/related properties) are changing, using a DataTrigger, for example? The previous examples have used CellValuePresenter. This example uses LabelPresenter. Are either of these the right thing when dealing with UnboundField? So far my attempts with CellValuePresenter have not worked properly.
2. What is the best way to bind, inside that style, to a property of the bound object for the cell? The previous example uses Record.DataItem.XXX. I'd like to refer to the actual bound property for the specific cell, not to the general Record.DataItem (that all cells in that row are bound to). The new example overrides the Template property of the LabelPresenter, and then accesses the TemplatedParent.Content inside the binding for a ContentPresenter. I think this may be getting closer to what I need - but I'm still trying to understand what it all means.
3. Once I've got the right thing for steps 1 and 2 above, what is the best way to design my StoryBoard ColorAnimation so that it can effect the background color of that thing? The previous example used the syntax "(Panel.Background).(SolidColorBrush.Color)", which I don't fully understand - but that does seem to work for Field, and not for UnboundField - so I'm not sure why, or what I should change to make that work?
Hello,
I have modified the sample from the post you referred and everything seems to work ok on my side, when I used UnboundFields instead of Fields. If the sample doesn’t satisfies all your needs feel free to modify it, so it reproduces your behavior and send it back to me for further investigation.
Looking forward for your reply.
Thanks for the update. You're right, this one works fine - seems the change from (Panel.Background) to (Background) in the animations is one of the things that helps.
I've taken this updated version, and imported some of my basic PropertyModel stuff to get it much closer to what I am trying to do. Have a look at this version - it is still basically doing the same thing, but now using PropertyModel properties and binding the UnboundField to Entity.Property.Value instead of just Entity.Property. It does seem to still work for the most part.
There is one issue with this implementation that I can see already. If you let it run for a while and watch it, you'll notice some of the updates miss their cell highlighting. Specifically, this happens when a field is updated, and then the next field to be updated is on the same row. This is now more evident in my example, because I have lengthened the "dirty" time to a full second, so you can get another update before the first dirty flag goes away. I think this is because all of the update logic depends on the entire row and not on individual cell properties.
The bigger issue which I would like to resolve (and which would also probably help address that first problem) is the fact that the MultiBinding is working on the Record.DataItem, and using the converter to go in and find the individual field from the entity, based on the CellValuePresenter.Field.Name property (so I guess this assumes my Name always matches the property in my BindingPath). Isn't there something other than Record.DataItem that we can get to from within the XAML directly? Something like CellValuePresenter.BoundData or something? I'm sure I'm just missing it..
Thanks again.
Ok here's a bit of an update on that last sample I sent. This one isn't quite working properly as you will see, but it is moving in the direction I would like to go. A few things to mention:
1. Replaced the IsEntityDirty flag (which changed only on/off for the entire record, thus missing the intra-row changes) with a DirtyProperties array of the names of all dirty properties - this will raise an update every time there is any change to the set of dirty fields on the row. As you will see when you run it, this fixes the problem of updated fields on the same row not flashing.
2. Changed the binding of the UnboundFields to go straight to the PropertyModel itself, not the PropertyModel.Value. What I am trying to accomplish here is to give the bound cell template full access to the various attributes of the PropertyModel (in the future imagine we could add a bunch of useful things here, such as a user-configurable string format for numbers, colors/formats/styles, modifiers, etc.) So if your data context is the entire PropertyModel, I hope you can get to all those individual attributes from within the templates/styles for the cell. This isn't working right now because my attempts to override the content presenter / template to bind to the PropertyModel.Value did not work - see the commented out stuff in the XAML to get an idea of what I was trying. For example, applying a style directly to XamTextEditor, or applying an override to the ContentTemplate on the CellValuePresenter. So for now, what you see in each cell is just the full name of the bound property model type.
3. If we are able to find a way to accomplish #2 above, my hope is that the trigger for the row flashing can become much more simple, and eliminate the need for the Entity object to track the dirty changes of all its properties. So for example I tried to implement a very simple DataTrigger (instead of the complicated MultiBinding currently there) which just binds directly to the PropertyModel IsDirty property. I wasn't able to get this to work, because I'm not sure how to resolve the PropertyModel (which can be done with a converter from the CellValuePresenter) and then access the IsDirty property from it after the converter. See my commented code to see what I was trying. I know the entire thing can be done in a converter - but in that case presumably you won't get the notify change updates that you need for the IsDirty flag?
I'm sure this mostly comes down to my limitations in understanding the best way to do this in WPF. But I'm hoping there is a cleaner solution here, and hopefully I'm just missing a couple of simple things.
Thanks again!
Hello Michel,
Thank you for the provided info and sample. I believe that the approach you use with IsDirty Property is the best one for achieving the functionality you want, but if I think of a better one, I will let you know.