Replies: 2 comments 1 reply
-
Upon first glance your event definition looks rather strange - you don't tend to make those a BindableProperty. What happens if you try public event EventHandler<ContactTypeSelectionArgs> FilterChanged; Also for your question on getting the event args in as a parameter, this should just happen for you and you shouldn't need to set anything else up. |
Beta Was this translation helpful? Give feedback.
-
Hi @bijington! Many thanks! that was everything! I was carrying this code from previous samples (in WPF) and tests, it was simpler, and I was struggling with an invalid event definition... With your proposed change, everything now works as expected, and I' receiving the param as well without any problem. //
public event EventHandler<ContactTypeSelectionArgs> FilterChanged;
//
public void OnTapGestureRecognizerTapped(object sender, TappedEventArgs args)
{
var selection = (ContactTypeElement)args.Parameter!;
FilterChanged?.Invoke(this, new ContactTypeSelectionArgs { TypeSelected = (ContactTypeEnum)selection.Id });
}
// <controls:ContactTypeSelectorControl ContactTypes="{Binding ContactTypes}" Margin="10" x:Name="contactType">
<controls:ContactTypeSelectorControl.Behaviors>
<toolkit:EventToCommandBehavior
x:TypeArguments="controls:ContactTypeSelectionArgs"
EventName="FilterChanged"
Command="{Binding FilterChangedCommand}" />
</controls:ContactTypeSelectorControl.Behaviors>
</controls:ContactTypeSelectorControl> Thanks again! |
Beta Was this translation helpful? Give feedback.
-
Hi Community!
I am trying to bind an event raised from a UserControl that is reused in other places of my .NET MAUI app.
This UserControl, brom the code behind raises and event called FilterChanged.
Now, trying to capture this event from one page, I found this behaviour that on paper, fits my requirements.
However, once I try to use it, I'm never able to start the app, what am I doing wrong? How is it supposed to be used?
XAML:
ViewModel:
Error
I've tried several ways, including using AncestorType and always having the same problem.
Additionally, how can I capture the param from the event into the Command Handler? Do I need to specify a CommandParameter for this?
Many thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions