Hello,
I have used the xamdatagrid and created some trigger event with the help of interaction Triggers.
I have written its method in view model but Its not working data binding is working proerly for grid but theres some issues in binding trigger. Please find below code snippes .
I have aslo attached the code sample which might be useful to undestand my issues.
<i:Interaction.Triggers> <i:EventTrigger EventName="CellUpdated" SourceName="xamDataGrid1"> <ei:CallMethodAction MethodName="{Binding Path= xamDataGridCellUpdated}" TargetObject="{Binding ElementName=TestViewModel}"/> </i:EventTrigger> <i:EventTrigger EventName="CellActivating" SourceName="xamDataGrid1"> <ei:CallMethodAction MethodName="{Binding Path= xamDataGridCellActivating}" TargetObject="{Binding ElementName=TestViewModel}"/> </i:EventTrigger>
</i:Interaction.Triggers>
Looking forward for your kind relay.
Hello Jay,
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
Hi Stefan,
It works !!!!!! :)
Many Many Thanks !!! You really help me lot to resolve this !!! you are really amazing !!!
Thx ,
JaY
I have been looking into your requirement and in that case I suggest you use the following code:
<igDP:XamDataGrid Grid.Row="1" AutoFit="False" MaxHeight ="660" Width="545" DataSource="{Binding Path=EmpList,Mode=TwoWay}" DataContext="{Binding UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Stretch" x:Name="xamDataGrid1" VerticalAlignment="Stretch" BorderBrush="Black" Theme="RoyaleStrong" BorderThickness="1" Margin="10,10,10,10" Height="260" > <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings HighlightAlternateRecords="True" AutoGenerateFields="True" AllowAddNew="False"></igDP:FieldLayoutSettings> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldSettings > <igDP:FieldSettings AllowEdit="True" AllowGroupBy="False" AllowRecordFiltering="True"></igDP:FieldSettings> </igDP:XamDataGrid.FieldSettings> <i:Interaction.Triggers> <i:EventTrigger EventName="CellUpdated" SourceName="xamDataGrid1"> <ei:CallMethodAction MethodName="xamDataGridCellUpdated" TargetObject="{Binding}"/> </i:EventTrigger> <i:EventTrigger EventName="CellActivating" SourceName="xamDataGrid1"> <ei:CallMethodAction MethodName="xamDataGridCellActivating" TargetObject="{Binding}"/> </i:EventTrigger> </i:Interaction.Triggers> </igDP:XamDataGrid>
Basically I changed the DataContext of the XamDataGrid and its DataSource binding, so that I can use the DataContext in the EventTriggers. Pease let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
Thank you very much for prompt reply.
I have tried with this statice resouces but in that case my Viewmodel Constructor is getting called twice.
In our scenario , we are actully adding differenct usercontrol(view) based on Ribbon control button click event into content place holder and if you check the MainwindowResource file , there we have provide the databinding between the view and viewmodel. If I remove that binding and kept only your statice binding it will not getting display.
So, thats issues i was facing right now. Kindly suggest solution for this.
Thx,
Jay
Thank you for your post. I have been looking into it and the sample project you have attached and I suggest you use the following code for the Interaction instead of yours:
<i:Interaction.Triggers> <i:EventTrigger EventName="CellUpdated" SourceName="xamDataGrid1"> <ei:CallMethodAction MethodName="xamDataGridCellUpdated" TargetObject="{StaticResource myVM}"/> </i:EventTrigger> <i:EventTrigger EventName="CellActivating" SourceName="xamDataGrid1" > <ei:CallMethodAction MethodName="xamDataGridCellActivating" TargetObject="{StaticResource myVM}"/> </i:EventTrigger> </i:Interaction.Triggers>
Also you should add this to the Resources of your XamDataGrid:
<igDP:XamDataGrid.Resources> <local:TestViewModel x:Key="myVM"/> </igDP:XamDataGrid.Resources>
And this namespace, too:
xmlns:local="clr-namespace:SpreadsheetFramework.Client.ViewModel"
Please let me know if this helps you or you need further assistance on this matter.