- Home
- Forum
- Xamarin.Forms
- Command Linking To Value Changed
Command Linking To Value Changed
I'm having trouble getting a event to behavior command linked to when my SfNumericUpDown value changes.
I have an SfNumericUpDown within a ListView and I'm having a difficult time interpreting which item in the list I'm working with because I can't figure out which EventName into my EventToCommandBehavior.
Any ideas?
Normally I can do something like this:
<Entry.Behaviors>
<helper:EventToCommandBehavior
EventName="ThisWouldBeTheEventForValueChanged"
Command="{Binding DoSomethingCommand}"
CommandParameter="{Binding Source={x:Reference ThisIsTheListForReference}}"/>
</Entry.Behaviors>
SIGN IN To post a reply.
1 Reply
1 reply marked as answer
RS
Ramya Soundar Rajan
Syncfusion Team
July 27, 2020 02:13 PM UTC
Hi Matthew,
Greetings from Syncfusion.
We have achieved your requirement with EventToCommandBehavior for SfNumericUpDown ValueChanged event. Added the SfNumericUpDown control inside the ListView as like in the below code snippet.
[XAML]
|
<ListView x:Name="listView" ItemsSource="{Binding ItemCollection }" ItemSelected="ListView_ItemSelected" ItemTapped="ListView_ItemTapped">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<numeric:SfNumericUpDown x:Name="numericUpDown" Value="{Binding NumericValue}">
<numeric:SfNumericUpDown.Behaviors>
<local:EventToCommandBehavior EventName="ValueChanged" Command="{Binding ValueChangedCommand}" CommandParameter="{x:Reference numericUpDown}"/>
</numeric:SfNumericUpDown.Behaviors>
</numeric:SfNumericUpDown>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView> |
[C#]
|
public class ViewModel : BindableObject
{
public IList<Contacts> ItemCollection { get; private set; }
public ViewModel()
{
ItemCollection = new List<Contacts>();
for (int i = 1; i < 10; i++)
{
ItemCollection.Add(new Contacts() { NumericValue = i });
}
}
}
public class Contacts
{
public Contacts()
{
ValueChangedCommand = new Command(NumericValueChangedEvent);
}
private void NumericValueChangedEvent(object args)
{
}
private int numericValue;
public int NumericValue
{
get { return numericValue; }
set { numericValue = value; }
}
public ICommand ValueChangedCommand { get; private set; }
} |
Please let us know if you have any concerns.
Regards,
Ramya S
Marked as answer
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
- Marked answer
-
MB Matthew Bailey
- Jul 24, 2020 11:51 AM UTC
- Jul 27, 2020 02:13 PM UTC