This is a migrated thread and some comments may be shown as answers.

How to refresh a EventBinding bounded Command Class?

2 Answers 223 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 20 Jun 2018, 05:38 PM
Hi Telerik ,

i have some problem to find a solution here for ..
first i am using RadGridView + MVVM + QueryableCollectionView.

The "pattern" is like this
My ViewModel  has a property named "Nodes" which is a derived class of  QueryableCollectionView which i am using because of paging feature.
The Problem i have is that the QueryableCollectionView is a wrapper for a IQueryable sourceCollection which is only set by constructor and there is not setter
for the wrapped source collection after its constructed.

So ok, i have done a workaround and creating a new Instance during RT of QueryableCollectionView with correct IQueryable parameter ( which by the way i do not have before ) and
set my ViewModel "Nodes" property to this new instance.

This works and i can see the Data correctly also paging works because the Grid gets notified about the change. ( it looks like so !)

In the "Nodes" Class i also have a "Command" property which is an Instance of a CommandProviderClass derived from prism.mvvm BindableBase ( which implements INotifyPropertyChanged )
and additionaly encapsulates a lot of other possible commands for Insert/Update/Delete .

And this "Command" property also gets replaced by the  "newer" instance of "Nodes" because the Nodes Class holds this property.
My ViewModel has a wrapper to this Nodes.CommandProvider

BUT ...


So now my Problem is raised during the Event "RowValidating" i found that the  User Control is still bound to old CommandProvider.DoValidatingRow 

because   

public ICommand DoValidatingRow { get; set; } // On Validate a Row
.... is initialized with
DoValidatingRow = new DelegateCommand<object>(OnValidatingRow);
 
But ICommand and DelegateCommand (Prism.Commands) Class have no INotifyPropertyChanged Contract defined.
 
<telerik:EventBinding Command="{Binding CommandProvider.DoValidatingRow}" EventName ...

i already also called on my VM   this.RaisePropertyChanged(""); before the validation is called but no effect. It´s doesn´t change!

A) So my main Question is how can i tell the User Control to refresh all of it´s bounded Class Instances ?

B) Maybe is there another solution to replace the wrapped Source Collection in QueryableCollectionView , because this will solve the original problem ?

thanks br thomas cinatl


        <telerik:RadGridView x:Name="LookupListGridCtrl" ItemsSource="{Binding Nodes, Mode=TwoWay}" SelectedItem="{Binding Nodes.SelectedUiDataItem,Mode=TwoWay}"  Grid.Row="1"
                             AutoGenerateColumns="false" GroupRenderMode="Flat" NewRowPosition="Top" SelectionMode="Single" SelectionUnit="FullRow"
                             CanUserDeleteRows="True" ScrollMode="Deferred" IsSynchronizedWithCurrentItem="True" CanUserResizeColumns="True" CanUserSearch="True"
                             RowIndicatorVisibility="Visible" Margin="0,0,0,1" ValidationType="Default"
                             FilteringMode="FilterRow" ShouldCloseFilteringPopupOnKeyboardFocusChanged="True"
        >
 
            <telerik:EventToCommandBehavior.EventBindings>
                <telerik:EventBinding Command="{Binding CommandProvider.DoDeleteRow}" EventName="Deleted" RaiseOnHandledEvents="True" PassEventArgsToCommand="True" />
                <telerik:EventBinding Command="{Binding CommandProvider.DoInsertRow}" EventName="RowEditEnded" RaiseOnHandledEvents="True" PassEventArgsToCommand="True" />
                <telerik:EventBinding Command="{Binding CommandProvider.DoAddNew}" EventName="AddingNewDataItem" RaiseOnHandledEvents="True" PassEventArgsToCommand="True" />
                <telerik:EventBinding Command="{Binding CommandProvider.DoValidatingCell}" EventName="CellValidating" RaiseOnHandledEvents="True" PassEventArgsToCommand="True" />
                <telerik:EventBinding Command="{Binding CommandProvider.DoValidatingRow}" EventName="RowValidating" RaiseOnHandledEvents="True" PassEventArgsToCommand="True" />
                <telerik:EventBinding Command="{Binding CommandProvider.DoSelectionChanging}" EventName="SelectionChanging" RaiseOnHandledEvents="True" PassEventArgsToCommand="True" />
            </telerik:EventToCommandBehavior.EventBindings>







 

2 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 22 Jun 2018, 03:50 PM
Hi Thomas,

Thank you for the description of your setup.

I may be missing something here, because a PropertyChanged notification is not meant to be raised from the ICommand implementation. It needs to be raised from the property setter instead, as follows.
private ICommand doValidatingRow;
public ICommand DoValidatingRow
{
    get { return this.doValidatingRow; }
    set
    {
        this.doValidatingRow = value;
        this.OnPropertyChanged("DoValidatingRow");
    }
}

Is the ICommand binding updated with such an approach?

Regards,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Thomas
Top achievements
Rank 1
answered on 23 Jun 2018, 11:08 AM

Thanks Stefan ,

i found yesterday , your post is correct instead of changing the property i changed the field which did not raised the notification.

Thanks br.

Tags
GridView
Asked by
Thomas
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Thomas
Top achievements
Rank 1
Share this question
or