I get the following XML when I call XamDataGrid.SaveCustomizations(). Why do I get the second fieldlayout when the grid clearly has just one fieldlayout? Also, keys for these additional layouts are are empty strings. How do i prevent this from happening?
"<?xml version=\"1.0\" encoding=\"utf-8\"?><xamDataPresenter version=\"10.3.20103.2018\" formatVersion=\"1.6\">
<fieldLayouts>
<fieldLayout key=\"SitMessage\" fieldList=\"State;ObjectState, Key;Int64, TimeStamp;DateTime, MessageNumber;Int64, Source;DbItem, Destination;DbItem, ReceiveTime;DateTime, TransmitTime;DateTime, ModifiedSitType, BeaconId15Hex, Satellite;DbItem, Filename, Validity;SitValidity, NotificationText\">
<sortedFields>
<sortedField extendedInfo=\"TimeStamp;DateTime\" direction=\"Descending\" fieldName=\"TimeStamp\" isGroupBy=\"false\" />
</sortedFields>
<fields>
<field name=\"State\" extendedInfo=\"State;ObjectState\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"Key\" extendedInfo=\"Key;Int64\" cellWidthAuto=\"true\" labelWidthAuto=\"true\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"TimeStamp\" extendedInfo=\"TimeStamp;DateTime\" cellWidthAuto=\"true\" labelWidthAuto=\"true\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"MessageNumber\" extendedInfo=\"MessageNumber;Int64\" cellWidthAuto=\"true\" labelWidthAuto=\"true\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"Source\" extendedInfo=\"Source;DbItem\" cellWidthAuto=\"true\" labelWidthAuto=\"true\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"Destination\" extendedInfo=\"Destination;DbItem\" cellWidthAuto=\"true\" labelWidthAuto=\"true\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"ReceiveTime\" extendedInfo=\"ReceiveTime;DateTime\" cellWidthAuto=\"true\" labelWidthAuto=\"true\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"TransmitTime\" extendedInfo=\"TransmitTime;DateTime\" cellWidthAuto=\"true\" labelWidthAuto=\"true\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"ModifiedSitType\" extendedInfo=\"ModifiedSitType\" cellWidthAuto=\"true\" labelWidthAuto=\"true\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"BeaconId15Hex\" extendedInfo=\"BeaconId15Hex\" cellWidthAuto=\"true\" labelWidthAuto=\"true\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"Satellite\" extendedInfo=\"Satellite;DbItem\" cellWidthAuto=\"true\" labelWidthAuto=\"true\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"Filename\" extendedInfo=\"Filename\" cellWidthAuto=\"true\" labelWidthAuto=\"true\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"Validity\" extendedInfo=\"Validity;SitValidity\" cellWidthAuto=\"true\" labelWidthAuto=\"true\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"NotificationText\" extendedInfo=\"NotificationText\" cellWidthAuto=\"true\" labelWidthAuto=\"true\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" />
</fields>
</fieldLayout>
<fieldLayout key=\"\" fieldList=\"State;Object, Key;Object, TimeStamp;Object, MessageNumber;Object, Source;Object, Destination;Object, ReceiveTime;Object, TransmitTime;Object, ModifiedSitType;Object, BeaconId15Hex;Object, Satellite;Object, Filename;Object, Validity;Object, NotificationText;Object\">
<sortedField extendedInfo=\"TimeStamp;Object\" direction=\"Descending\" fieldName=\"TimeStamp\" isGroupBy=\"false\" />
<field name=\"State\" extendedInfo=\"State;Object\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"Key\" extendedInfo=\"Key;Object\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"TimeStamp\" extendedInfo=\"TimeStamp;Object\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"MessageNumber\" extendedInfo=\"MessageNumber;Object\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"Source\" extendedInfo=\"Source;Object\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"Destination\" extendedInfo=\"Destination;Object\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"ReceiveTime\" extendedInfo=\"ReceiveTime;Object\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"TransmitTime\" extendedInfo=\"TransmitTime;Object\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"ModifiedSitType\" extendedInfo=\"ModifiedSitType;Object\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"BeaconId15Hex\" extendedInfo=\"BeaconId15Hex;Object\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"Satellite\" extendedInfo=\"Satellite;Object\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"Filename\" extendedInfo=\"Filename;Object\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"Validity\" extendedInfo=\"Validity;Object\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" /> <field name=\"NotificationText\" extendedInfo=\"NotificationText;Object\" Visibility=\"Visible\" IgnoreFieldVisibilityOverrides=\"false\" />
</fieldLayouts>
</xamDataPresenter>
Also, grid gets into a state where it keeps adding feild layouts to the serialized string sometimes with empty keys. Other times, field layout being added is from the previous data type that was displayed in the grid. Please help.
Looks like XamDataGrid.SaveCustomizations() is not clearing some cache or buffer somewhere.
For example, this is my latest serialized string, even though I see FieldLayouts.Count ==1 just prior to calling XamDataGrid.SaveCustomizations().
<?xml version="1.0" encoding="utf-8"?>
<xamDataPresenter version="10.3.20103.2018" formatVersion="1.6">
<fieldLayout key="" fieldList="State;Object, Key;Object, TimeStamp;Object, Severity;Object, Source;Object, SourceType;Object, ProcessName;Object, Message;Object">
<sortedField extendedInfo="TimeStamp;Object" direction="Descending" fieldName="TimeStamp" isGroupBy="false" />
<field name="State" extendedInfo="State;Object" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="Key" extendedInfo="Key;Object" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="TimeStamp" extendedInfo="TimeStamp;Object" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="Severity" extendedInfo="Severity;Object" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="Source" extendedInfo="Source;Object" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="SourceType" extendedInfo="SourceType;Object" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="ProcessName" extendedInfo="ProcessName;Object" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="Message" extendedInfo="Message;Object" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<fieldLayout key="" fieldList="State;Object, Key;Object, TimeStamp;Object, MessageNumber;Object, Source;Object, Destination;Object, ReceiveTime;Object, TransmitTime;Object, ModifiedSitType;Object, BeaconId15Hex;Object, Satellite;Object, Filename;Object, Validity;Object, NotificationText;Object">
<field name="MessageNumber" extendedInfo="MessageNumber;Object" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="Destination" extendedInfo="Destination;Object" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="ReceiveTime" extendedInfo="ReceiveTime;Object" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="TransmitTime" extendedInfo="TransmitTime;Object" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="ModifiedSitType" extendedInfo="ModifiedSitType;Object" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="BeaconId15Hex" extendedInfo="BeaconId15Hex;Object" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="Satellite" extendedInfo="Satellite;Object" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="Filename" extendedInfo="Filename;Object" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="Validity" extendedInfo="Validity;Object" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="NotificationText" extendedInfo="NotificationText;Object" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<fieldLayout key="SitMessage" fieldList="ActionRequestedState;ObjectState, TimeStamp;DateTime, MessageNumber;Int64, Source;DbItem, SourceType;EntityType, Destination;DbItem, SitType;Int32, ModifiedSitType, TypeAlias;SitTypeAlias, Satellite;DbItem, SatelliteType;EarthOrbit, Validity;SitValidity, TransmitState;SITTransmitState, AuthStatus;SITAuthStatus, CommsHandler, ReceiveTime;DateTime, TransmitTime;DateTime, Direction;MessageDirection, NotificationText, BeaconId15Hex, Body;Object, Notification;SITNotification, State;ObjectState, IsActive;Boolean, Key;Int64, Filename, IsSelected;Boolean, IsActiveSelected;Boolean">
<field name="ActionRequestedState" extendedInfo="ActionRequestedState;ObjectState" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="TimeStamp" extendedInfo="TimeStamp;DateTime" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="MessageNumber" extendedInfo="MessageNumber;Int64" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="Source" extendedInfo="Source;DbItem" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="SourceType" extendedInfo="SourceType;EntityType" Visibility="Collapsed" IgnoreFieldVisibilityOverrides="false" />
<field name="Destination" extendedInfo="Destination;DbItem" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="SitType" extendedInfo="SitType;Int32" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="ModifiedSitType" extendedInfo="ModifiedSitType" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="TypeAlias" extendedInfo="TypeAlias;SitTypeAlias" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="Satellite" extendedInfo="Satellite;DbItem" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="SatelliteType" extendedInfo="SatelliteType;EarthOrbit" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="Validity" extendedInfo="Validity;SitValidity" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="TransmitState" extendedInfo="TransmitState;SITTransmitState" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="AuthStatus" extendedInfo="AuthStatus;SITAuthStatus" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="CommsHandler" extendedInfo="CommsHandler" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="ReceiveTime" extendedInfo="ReceiveTime;DateTime" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="TransmitTime" extendedInfo="TransmitTime;DateTime" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="Direction" extendedInfo="Direction;MessageDirection" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="NotificationText" extendedInfo="NotificationText" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="BeaconId15Hex" extendedInfo="BeaconId15Hex" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="Body" extendedInfo="Body;Object" Visibility="Collapsed" IgnoreFieldVisibilityOverrides="false" />
<field name="Notification" extendedInfo="Notification;SITNotification" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="State" extendedInfo="State;ObjectState" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="IsActive" extendedInfo="IsActive;Boolean" Visibility="Collapsed" IgnoreFieldVisibilityOverrides="false" />
<field name="Key" extendedInfo="Key;Int64" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="Filename" extendedInfo="Filename" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="IsSelected" extendedInfo="IsSelected;Boolean" Visibility="Collapsed" IgnoreFieldVisibilityOverrides="false" />
<field name="IsActiveSelected" extendedInfo="IsActiveSelected;Boolean" Visibility="Collapsed" IgnoreFieldVisibilityOverrides="false" />
Anyone there?
Even after clearing XamDataGrid.FieldLayout, when I call XamDataGrid.SaveCustomizations() I get the following XML. I NEED HELP HERE PLEASE.
<fieldLayout key="mySitMessage" fieldList="State;ObjectState, Key;Int64, TimeStamp;DateTime, MessageNumber;Int64, Source;DbItem, Destination;DbItem, ReceiveTime;DateTime, TransmitTime;DateTime, ModifiedSitType, BeaconId15Hex, Satellite;DbItem, Filename, Validity;SitValidity, NotificationText">
<sortedField extendedInfo="TimeStamp;DateTime" direction="Descending" fieldName="TimeStamp" isGroupBy="false" />
<fieldLayout key="SitMessage" fieldList="State;ObjectState, Key;Int64, TimeStamp;DateTime, MessageNumber;Int64, Source;DbItem, Destination;DbItem, ReceiveTime;DateTime, TransmitTime;DateTime, ModifiedSitType, BeaconId15Hex, Satellite;DbItem, Filename, Validity;SitValidity, NotificationText">
<field name="Key" extendedInfo="Key;Int64" cellWidthAuto="true" labelWidthAuto="true" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="TimeStamp" extendedInfo="TimeStamp;DateTime" cellWidthAuto="true" labelWidthAuto="true" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="MessageNumber" extendedInfo="MessageNumber;Int64" cellWidthAuto="true" labelWidthAuto="true" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="Source" extendedInfo="Source;DbItem" cellWidthAuto="true" labelWidthAuto="true" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="Destination" extendedInfo="Destination;DbItem" cellWidthAuto="true" labelWidthAuto="true" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="ReceiveTime" extendedInfo="ReceiveTime;DateTime" cellWidthAuto="true" labelWidthAuto="true" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="TransmitTime" extendedInfo="TransmitTime;DateTime" cellWidthAuto="true" labelWidthAuto="true" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="ModifiedSitType" extendedInfo="ModifiedSitType" cellWidthAuto="true" labelWidthAuto="true" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="BeaconId15Hex" extendedInfo="BeaconId15Hex" cellWidthAuto="true" labelWidthAuto="true" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="Satellite" extendedInfo="Satellite;DbItem" cellWidthAuto="true" labelWidthAuto="true" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="Filename" extendedInfo="Filename" cellWidthAuto="true" labelWidthAuto="true" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="Validity" extendedInfo="Validity;SitValidity" cellWidthAuto="true" labelWidthAuto="true" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field name="NotificationText" extendedInfo="NotificationText" cellWidthAuto="true" labelWidthAuto="true" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
<field nameSystem.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='ButtonNormalBackgroundFill'
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='ExpanderShadowFill'
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='ButtonNormalBackgroundFill'
="Notification" extendedInfo="Notification;SITNotification" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" />
Also, if I do the following:
dataGrid.FieldLayouts.Clear();
dataGrid.DefaultFieldLayout = null;
Console.WriteLine("============= After clearing profile =========");
Console.WriteLine(dataGrid.SaveValidCustomizations());
I see the same layout I posted above. What is going on here guys?
knji said: Fine and good. Then I change the field layout to another data type, call grid.ClearCustomizations and grid.FieldLayouts.Clear(), then re-attempt to restore the above customization using rid.LoadCustomizations(). All seems ok but I see rows of data with no fields. So, in the event handler of grid.FieldLayoutInitialized, I print out current customization as follows:
Fine and good. Then I change the field layout to another data type, call grid.ClearCustomizations
and grid.FieldLayouts.Clear(), then re-attempt to restore the above customization using
rid.LoadCustomizations(). All seems ok but I see rows of data with no fields.
So, in the event handler of grid.FieldLayoutInitialized, I print out current customization as follows:
knji said: I see second field layout has been injected with 0 fields. Where is this coming from and why is this happening?
I see second field layout has been injected with 0 fields. Where is this coming from and why is
this happening?
I meant loading creating another field layout based on a different data type. The view this grid is in supports different types of data, so I dynamically create a new field layout for the grid based on the selected data type but before doing this, I clear grid.Fieldlayouts and customizations using the following method:
private bool SetupGridFieldsLayout(FieldLayout fl)
{
bool fieldLayoutFound = false;
if (fl != null)
dataGrid.ClearUserSettings();
dataGrid.FieldLayoutSettings.AutoGenerateFields = false;
dataGrid.FieldLayouts.Add(fl);
fieldLayoutFound = true;
}
if (!fieldLayoutFound)
dataGrid.FieldLayoutSettings.AutoGenerateFields = true;
return fieldLayoutFound;
What you refer to layout file, I assume you are referring to the customization string I pass into LoadCustomizations. OK, now I understand that LoadCustomizations does not create field layout. So what happens? Let me see if I can understand this:
1-I call LoadCustomizations and pass a valid customization string
2. Grid stores information in a layout file.
3. I update my data collection, which fires CollectionChanged event
4. Grid starts creating field layout based on the following context:
- AutoGenerateFields is false
- Layout file has a valid customized string
5. What I see happening is that the grid is ignoring the valid customized string, and using the first one with 0 fields. Even if I change the key of the valid customized string so that it is not the same as the empty field layout created, the grid still does not pick up this valid customization.
You say" it simply stores the customization information until there is a field layout whose key and field list matches that of the information from the loaded customizations at which point the customizations are applied to that field layout."
What does this mean? Grid creates field layout with a key based on data type name, goes to layout file and matches layout, then uses this information to complete initialization of field layout?
If this is so, why does it not match layout I loaded from customized string instead of creating a field layout with same key but 0 fields?
Sorry for all the questions but I am thoroughly confused here.
knji said: You say" it simply stores the customization information until there is a field layout whose key and field list matches that of the information from the loaded customizations at which point the customizations are applied to that field layout." What does this mean? Grid creates field layout with a key based on data type name, goes to layout file and matches layout, then uses this information to complete initialization of field layout?
knji said: If this is so, why does it not match layout I loaded from customized string instead of creating a field layout with same key but 0 fields?
Well explained Andrew. I now get it.
LoadCustomizations has nothing to do with creation of field layouts. In other words, the grid field layouts MUST be created, either by specifying AutoGenerateFields to true or explicitly by adding a FieldLayout instance to the FieldLayouts collection, before customizations are loaded.
In my case, I am setting AutoGenerateFields to false, to control what fields are displayed from the data type. However, in this case, I needed to first create the field layout before applying the customization. I get it.
Changed things around and all is working well, thank you, thank you, thank you.
One request though: Please do not let post like these sit for more than 1 day before responding. If I had this information earlier, which I could not find in your online doc, I would not have spent 4 days on this problem.
Thanks again.
Klaus
From what I understand, If I have saved customizations and next time before loading those if the field list gets modified [add or delete a few fields] the saved fieldLayout will not be restored even if the key is matching. Is there any way to preserve the field customizations even if the field list changes?