Hello,
I'm having issue with the XamDataGrid Initialized event. Somehow it is not firing when using interaction triggers.
<igDP:XamDataGrid x:Name="myXamDataGrid"> <i:Interaction.Triggers> <i:EventTrigger EventName="Initialized"> <i:InvokeCommandAction Command="{Binding myCommand}" /> </i:EventTrigger> </i:Interaction.Triggers> </igDP:XamDataGrid>
Hello User201,
Thank you for your update. It is expected that the Loaded event will fire when switching tabs, as the Loaded event is fired when an element is added to the visual tree of a WPF application.
If you wish to handle the Initialized event in an MVVM way, I would recommend writing a new Behavior<XamDataGrid> and applying it using the Interaction.Behaviors attached property. In the Behavior, you can override the OnAttached method and hook into the Initialized method. This appears to happen early enough that you can handle the event.
I have attached a sample project to demonstrate the above.
Please let me know if you have any other questions or concerns on this matter.
8371.XDGInitializedMVVM.zip
Sincerely,AndrewAssociate Developer
Hello Andrew,
I have many XamDataGrids in different tabs. Using the Loaded event would fire each time when switching back to that specific tab.
I have been investigating into this behavior, and there does not appear to be a way to handle the Initialized event using an EventTrigger.
The XamDataGrid.InitializedEvent is inherited from FrameworkElement, and so if you were to try the same EventTrigger on something like a Button, it would not work either. I am not entirely sure when exactly triggers and attached properties are actually "attached" to a WPF FrameworkElement, to be honest, but I would recommend handling the Loaded event in your EventTrigger instead, as that appears to fire the command normally.
Is there a particular reason you need to handle the Initialized event via an EventTrigger => InvokeCommandAction in this case?