Click here to Skip to main content
15,880,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am using MVVM model for my application. I have 2 Views that contains a GridView each. Both of them are binding to the same command in the ViewModel for GridView's selection changed.

<GridControl Grid.Row="0" Grid.Column="1" x:Name="TaskItemsGridView" SelectionChangedCommand=" {Binding ShowSelectedTaskCommand}" ItemsSource="{Binding ActiveTaskList, Mode=TwoWay}" SelectedItem="{Binding ActiveTask, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>

ShowSelectedTaskCommand is invoking a function that performs some functions and updates ActiveTask.

I am facing two issues here.

a) I need to do an additional db save after which the ActiveTask will be set , when selection changed command is invoked from View1. My issue is even if I make the commands separate to handle this situation, both the commands are executed as I need to update ActiveTask in between. So if one command updates ActiveTask, it will fire SelectionChanged for other command. How can i tackle this situation. b) Since both functions are called in both cases, how can I add some condition to perform db save.

Below is my func for reference

C#
private void ShowSelectedTask()
        {
            if (ActiveTask.EventId != TaskId && !string.IsNullOrEmpty(ActiveTaskName))
                UpdateTaskInformation(TaskId); // It updates ActiveTask

              // TO DO: DB save to be performed if this command is invoked from View1.

            if (ActiveTask != null)
            {
                TaskId = ActiveTask.EventId;
                ....

            }
        }

Note: The only difference in the functionalities from both the view is the additional db save. Rest of the code are common for both. Please help.

Thanks
Posted
Updated 24-Sep-14 7:38am
v6

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900