Hi,
I'm having an issue getting an event to command linked when my SfNumericUpDown value changes.
I have a SfNumericUpDown within a Xamarin.Forms.DataTemplate and when I change SfNumericUpDown control it is not triggering my NumericValueChangedEvent method in my viewmodel. I used
EventToCommandBehavior to convert from event to command.
<StackLayout
x:Name="CartLayout"
Grid.Row="2"
BindableLayout.ItemsSource="{Binding CartItems}"
Spacing="16"
Margin="20"
VerticalOptions="Start">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Grid
BackgroundColor="{DynamicResource Gray-White}"
ColumnSpacing="0"
RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<numeric:SfNumericUpDown x:Name="numericUpDown" Value="{Binding Quantity}" Margin="10" Grid.Row="0">
<numeric:SfNumericUpDown.Behaviors>
<local:EventToCommandBehavior EventName="ValueChanged" Command="{Binding QtyCommand}" CommandParameter="{x:Reference numericUpDown}"/>
</numeric:SfNumericUpDown.Behaviors>
</numeric:SfNumericUpDown>
</Grid>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
C#
Command<ValueEventArgs> qtyCommand;
public Command<ValueEventArgs> QtyCommand
{
get { return qtyCommand; }
protected set { qtyCommand = value; }
}
qtyCommand = new Command<Syncfusion.SfNumericUpDown.XForms.ValueEventArgs>(NumericValueChangedEvent);
public void NumericValueChangedEvent(ValueEventArgs e)
{
Application.Current.MainPage.DisplayAlert("Qty", "Number:", "Ok");
}
I have attached the sample project I tried.
Any help is appreciated!!!!
|
…
<StackLayout x:Name="CartLayout"
…>
<BindableLayout.ItemTemplate>
<DataTemplate>
<Grid BackgroundColor="{DynamicResource Gray-White}">
…
<numeric:SfNumericUpDown x:Name="numericUpDown"
Value="{Binding Quantity}"
Margin="10"
Grid.Row="0">
<numeric:SfNumericUpDown.Behaviors>
<local:EventToCommandBehavior EventName="ValueChanged"
Command="{Binding BindingContext.QtyCommand, Source={x:Reference Name=CartLayout}}"/>
</numeric:SfNumericUpDown.Behaviors>
</numeric:SfNumericUpDown>
</Grid>
</DataTemplate>
</BindableLayout.ItemTemplate>
… |
Thanks, Vignesh for the quick response. Now SfNumericUpDown ValueChanged event is working inside DataTemplate after bindingcontext is added to the command.
Thanks a lot 🙏.