Hello,
I am using a XamDataGrid with the datasource bound to a collection of interfaces, which are resolved to the respective classes via UnityContainer. The fields are defined with namebinding, underlying types are short, string, int?, decimal?. RecordContainerGenerationMode is not set, so judging from the blog I found click here it is set to recycle.
Now to my problem: the values in cells whose types are nullable, like int? or decimal?, are sometimes horizontal aligned left sometimes right and this behavior is not coherent over the rows. Row 1 and 2 can be correctly aligned right, Row 3 is aligned left, Row 4 is right, and some are empty because of the null value. Which cells are aligned wrong is random and changes with scrolling. There is no styling on the grid.
This behavior is fixed if I set RecordContainerGenerationMode to anything other than recycle, or if I change the underlying type to int eg. decimal (what I do not want). Setting the RecordContainerGenerationMode to anything other than recycle, results in a feelable performance decrease either in scrolling or on the initialization of the view.
I tried to define a style for XamNumericEditor and XamCurrencyEditor to always align right and I can see these settings in Snoop, but the values are still displayed left. For the wrongfully aligned cells, if I check the settings with snoop, there is no hint on why they are displayed left.
Regards
<igEditors:XamDataGrid DataSource="{Binding Children, ValidatesOnNotifyDataErrors=True}" ActiveDataItem="{Binding SelectedItem, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=False}"> <igEditors:XamDataGrid.FieldSettings> <dataPresenter:FieldSettings AllowRecordFiltering="True" AllowEdit="False" AllowSummaries="False" /> </igEditors:XamDataGrid.FieldSettings> <igEditors:XamDataGrid.FieldLayouts> <dataPresenter:FieldLayout> <dataPresenter:FieldLayout.SortedFields> <dataPresenter:FieldSortDescription FieldName="ProduktId" Direction="Ascending" /> </dataPresenter:FieldLayout.SortedFields> <dataPresenter:Field Name="ProduktId"/> <dataPresenter:Field Name="Status"/> <dataPresenter:Field Name="FirmaBezeichnung"/> <dataPresenter:Field Name="ProduktCode"/> <dataPresenter:Field Name="ProduktArtId"/> <dataPresenter:Field Name="ProduktBezeichnung"/> <dataPresenter:Field Name="MindestProduktLaufzeitInJahren"/> <dataPresenter:Field Name="DefaultProduktLaufzeitInJahren"/> <dataPresenter:Field Name="TarifBezeichnung"/> <dataPresenter:Field Name="GeschaeftsBereichBezeichnung"/> <dataPresenter:Field Name="ProduktMindestFolgePraemie"/> <dataPresenter:Field Name="ProduktMindestJahresPraemie"/> <dataPresenter:Field Name="AutomatischeVerlaengerung"/> </dataPresenter:Field> </dataPresenter:FieldLayout> </igEditors:XamDataGrid.FieldLayouts> </igEditors:XamDataGrid>
MindestProduktLaufzeitInJahren and DefaultProduktLaufzeitInJahren are of type int?
ProduktMindestFolgePraemie and ProduktMindestJahresPraemie are of type decimal?
Hello Matthias,
I have been investigating into this behavior you are reporting, and being that this behavior only happens for you when RecordContainerGenerationMode is set to “Recycle,” I would have to imagine it has something to do with the virtualization of the grid, but I cannot be sure as to what at the moment. I have put together a sample project in an attempt to reproduce this behavior, but at the moment, I cannot see the behavior you are seeing.
It is also worth noting that you should be able to align the content of your Field elements in a uniform way by setting the HorizontalContentAlignment property of the Field, rather than going to the editor.
I have attached the sample project I used to test this. Please test this project on your PC; whether or not it works correctly may help indicate the nature of this problem.
If the project does not work correctly, this indicates either a problem possibly specific to your environment, or a difference in the DLL versions we are using. My test was performed using version 18.2.20182.186 in Infragistics for WPF 2018.2.
If the project does show the product feature working correctly, this indicates a possible problem in the code of your application. It will help if you can provide a small, isolated sample application that demonstrates the behavior you are seeing.
Or, if this sample project is not an accurate demonstration of what you're trying to do, please feel free to modify it and send it back, or send a small sample project of your own if you have one.
Please let me know if you have any other questions or concerns on this matter.
XDGNullableTypeTest.zip
Hello again,
I got another problem with name binding. It seems that I'm unable to bind to properties that are defined on the base class of my view model. This is the same in your sample application. I get following error in vs output:
A new FieldLayout is being created because none of the supplied FieldLayouts matched for the following reasons: Fieldlayout: ' - 8 Fields - index = 0' was not matched because of the following reason: There was no property found with a name of: 'IsChecked'. Note: name matching is case sensitive.
Thank you for your updates on this matter. It sounds like this issue may have been a bug in version 17.2. I am glad it works for you in 18.2. Also, 18.2 should work fine with .NET Framework 4.5.2.
Regarding the issue with name-binding, I have modified my sample project such that the SampleData class now has a sub-class, and I am able to name-bind to the properties of that sub-class to show a Field for those properties. As such, I can’t seem to reproduce the behavior you are seeing. Attaching the sample project to this post.
2248.XDGNullableTypeTest.zip
Hello Andrew,
I can't reproduce it in the sample project either (I just made a mistake yesterday). But I'm not able to get it to work in one view in our application. I tried to create a sample project, but I am unable to reproduce the behavior. We got the (almost) following structure in our code:
public class SampleData : SampleDataBase<ISomeModelInterface>, ISampleData { public SampleData(string name, long? id, string userName, string number, decimal sum, decimal? otherSum) : base (number, sum, otherSum) { this.Name = name; this.Id = id; this.UserName = userName; } //i can bind to these public string Name { get; private set; } public long? Id { get; private set; } public string UserName { get; private set; } } public interface ISampleData : ISampleDataBase { string Name { get; } long? Id { get; } string UserName { get; } } public abstract class SampleDataBase<TModel> : SomeOtherBaseClass<TModel>, ISampleDataBase where TModel : class, ISomeModelBaseInterface { protected SampleDataBase(string number, decimal sum, decimal? otherSum) { this.Number = number; this.Sum = sum; this.OtherSum = otherSum; } // I cannot bind to these, Field Layout error Propertyname cannot be found but the values are displayed in the view. // on the grid there are 2 FieldLayout definitions one with all fields (typeof SampleData), one with 0 fields (typeof ISampleData) public string Number { get; private set; } public decimal Sum { get; private set; } public decimal? OtherSum { get; private set; } } public interface ISampleDataBase { string Number { get; } decimal Sum { get; } decimal? OtherSum { get; } }
As I mentioned in the comments, I get the PropertyName not found error for all the properties in SampleDataBase. But only in our main application not in the sample. I don't get why the error is thrown and a new FieldLayout is generated but the property value is correctly displayed in the field.
I am unsure why this would be happening in your application, as I have now modified the sample project such that it essentially uses the same data source that you have provided and all fields are found.
I am attaching this sample project. Again, this sample project was tested against version 18.2.20182.186.
As for the values being correctly displayed, I believe that I can explain this. The current FieldLayout on your end is essentially not being used as the one you have defined does not match your data item in some way. Since you have not set the FieldLayoutSettings.AutoGenerateFields property to “false,” this enables us to auto-generate a FieldLayout in the case that one is not found that is valid. I am still unsure why it is not valid in this case, though.
1172.XDGNullableTypeTest.zip
I'm sorry for my late response, I tried various constellations in our application. Only sometimes, the xamdatagrid seems to be unable to bind to inherited properties, on some views it works like in your sample application. If I use alternate bindings it always works without exceptions. If I use name binding the values are correctly displayed but I get the property not found exception in the output window. I'm also curious as why I always find 2 FieldLayouts. The first, which contains all fields, is of the type of the class itself, the other which contains no fields is of the type of the corresponding interface.
Edit: If I remove the inherited properties from the FieldLayout the layout type is of the Interface. If I add the Field back I get 2 FieldLayouts, one from the Interface with no Fields, one from the corresponding class with all the fields
Do you have any further ideas?
I think I've found the problem.
In the sample applications we don't use the UnityContainer to resolve the Interface and set the data collection to items of the resolved interface. In the sample application the FieldLayout type is always the type of the class itself. Using the UnityContainer to resolve the interfaces for the items in the collection the FieldLayout is generated from the interface. Which results in the binding exception, because the Interface itself has no property with the specified name, even if it inherits an interface which has the member. If I hide the member of the base interface in the derived interface with new, it works as expected.
I'm unsure on how to fix this because we heavily rely on the UnityContainer and I'm not realy a fan of adding the property to each of my interfaces and hide the base member.
Thank you for your update(s).
Regarding the two FieldLayouts, I think this is likely due to the error message that you are seeing that “a new FieldLayout is being created…” This will effectively keep your current FieldLayout but use the one that is being created. The one that is being created is being created because in your XAML, it does not appear that you currently have the XamDataGrid.FieldLayoutSettings.AutoGenerateFields property set to false – this defaults to true.
Regarding being able to explain why this is happening in the first place though, I am really not sure as I don’t believe I completely understand what is going on with the resolution of your interfaces. As I am really unsure what is happening and I have no experience at all with UnityContainer, would it be possible for you to please modify the sample project that I sent you such that it implements these pieces and reproduces the behavior you are seeing? Alternatively, if you have an isolated sample project of your own that reproduces this, then would it be possible for you to please provide that?