Cannot use EventTriggerBehavior with ScrollViewer's ViewChanged event - mvvm

I try to use EventTriggerBehavior with ScrollViewer's ViewChanged event:
<ScrollViewer x:Name="scrollViewer">
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="ViewChanged">
<core:InvokeCommandAction Command="{Binding AddNextCommand}"
CommandParameter="{Binding ElementName=scrollViewer}"/>
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
</ScrollViewer>
But it get an exception:
Windows.UI.Xaml.Markup.XamlParseException: 'The text associated with this error code could not be found.
Cannot add instance of type 'Microsoft.Xaml.Interactions.Core.EventTriggerBehavior' to a collection of type 'Microsoft.Xaml.Interactivity.BehaviorCollection'.
How to fix it?
I want to automate add new elements to view when ScrollViewer scrolls to bottom, are there other ways to do it? Thanks!

Cannot add instance of type 'Microsoft.Xaml.Interactions.Core.EventTriggerBehavior' to a collection of type 'Microsoft.Xaml.Interactivity.BehaviorCollection'.
Firstly, this error indicates that the element does not have an event called ViewChanged. This is caused by you didn't allocate SourceObject for EventTriggerBehavior that the behavior is attached to the wrong element which is not scrollViewer. You should set SourceObject like follows:
<core:EventTriggerBehavior EventName="PointerPressed" SourceObject="{Binding ElementName=scrollViewer}">
But even with this, you may get another error since ViewChanged may not be supported with WindowsRuntimeMarshal.AddEventHandler. Please try to invoke the ScrollViewer.ViewChanged event directly.
I want to automate add new elements to view when ScrollViewer scrolls to bottom, are there other ways to do it?
Looks like ISupportIncrementalLoading could help. Please try it.

Related

DataTriggerBehavior Binding to Property on ViewModel

I'm trying to bind a DataTriggerBehavior to a Property on my ViewModel, but it doesn't ever fire.
I've used DataTriggerBehaviors bound to various Properties of Controls with no trouble but can't get the VM binding to work.
DataContext is set to the VM.
I can see the binding value in debug but nothing triggers.
I've tested the InvokeCommandAction by changing the DataTriggerBehavior to an EventTriggerBehavior so that works fine.
<AppBarButton Icon="Library">
<i:Interaction.Behaviors>
<core:DataTriggerBehavior Binding="{Binding HelpPhase}" ComparisonCondition="Equal" Value="Add" >
<core:InvokeCommandAction Command="{Binding DataContext.StoreRateCommand, ElementName=LayoutRoot}"/>
</core:DataTriggerBehavior>
</i:Interaction.Behaviors>
</AppBarButton>
In VM (inherits VMBase that implements IPCN)
Private mHelpPhase As String
Public Property HelpPhase() As String
Get
Return Settings.HelpPhase
End Get
Set(value As String)
SetProperty(Settings.HelpPhase, value)
End Set
End Property
The EventTriggerBehavior listens for a specific event on its source and executes an action when the event is fired. It is different from the DataTriggerBehavior.
The DataTriggerBehavior performs an action when the data the behaviors is bound to meets a specified condition. In your question, when the bound data of the HelpPhase's value change to "Add", the behavior triggers an action to fire the command.
You should be able check if you have bind the HelpPhase to the DataTriggerBehavior and set the "Add" to the HelpPhase. You can bind the HelpPhase to Text property of TextBlock if the TextBlock show "Add".
There is an official DataTriggerBehavior sample, please refer the XamlBehaviors sample.

Adding suggestionItems Fails: "Cannot add direct child without default aggregation defined for control sap.m.SearchField"

I am adding a SearchField with suggestions in the XML view. When I execute, I get the error
Error: Cannot add direct child without default aggregation defined for control sap.m.SearchField.
Please tell me what mistake I am making.
<SearchField
placeholder="final search"
tooltip="Search for datastore source names"
suggestionItems="{/records}"
selectOnFocus="true"
>
<suggestionItems>
<SuggestionItem
text="{dbname}"
description="{dbname}"
/>
</suggestionItems>
</SearchField>
Try to have a look to this example
sap.m.Input
suggestionItems="{/ProductCollection}" is the collection with all the available entries, text="{Name}" is one of the attributes of the collection item.
Check this example without search help https://sapui5.hana.ondemand.com/sdk/explored.html#/sample/sap.m.sample.InputSuggestionsDynamic/preview or https://sapui5.hana.ondemand.com/sdk/explored.html#/sample/sap.m.sample.InputSuggestionsCustomFilter/preview
You must be using an old UI5 version. The aggregation suggestionItems was introduced in 1.34.
Here, you can see that the app crashes throwing the same error if run with the version lower than 1.34: https://jsbin.com/qepojux/edit?html,js,output
To see with which UI5 version the app is currently running, press Ctrl+Left Alt+Shift+P.
See also Versioning of SAPUI5.

Listen to ItemTapped Event in FreshMvvm

In my project I have a list view, now listening to SelectedItem change is easy, every tutorial has that, but I can't find anything on using ItemTapped event.
What do I bind the event to in the modelPage?
Thanks,
Mike
Since ItemTapped is an event and not a Command (or BindableProperty at all) you cannot use it directly from you PageModel.
They have invented something like Behaviors for this. With Behaviors you can turn an Event to a Command.
While there are third party plugins which do this like Corcav's one, it is also built into Xamarin.Forms now.
Let me explain it by the Corcav one, other implementations should be similar. Also I'm assuming you're using XAML.
First of all, install the NuGet and don't forget to include the right namespace into your page, which means adding something like: xmlns:behaviors="clr-namespace:Corcav.Behaviors;assembly=Corcav.Behaviors"
Now under your ListView declare your Behaviors like so:
<!-- ... more XAML here ... -->
<ListView IsPullToRefreshEnabled="true" RefreshCommand="{Binding RefreshDataCommand}" IsRefreshing="{Binding IsBusy}" IsVisible="{Binding HasItems}" ItemsSource="{Binding Items}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" CachingStrategy="RecycleElement">
<behaviors:Interaction.Behaviors>
<behaviors:BehaviorCollection>
<behaviors:EventToCommand EventName="ItemSelected" Command="{Binding ItemSelectedCommand}" />
</behaviors:BehaviorCollection>
</behaviors:Interaction.Behaviors>
<!-- ... more XAML here ... -->
Note that is is a collection, so you could add more if you want (also in other scenarios).
Also note that I did in fact user the SelectedItem as well. This is probably what you want because else the item you tapped will stay selected. So the SelectedItem property doesn't do much more than set it back to null (hence the TwoWay). But you can also take the actual selected item from there.
So now in your PageModel declare a Command and assign it with something like this:
private void ItemSelected()
{
// Open the article page.
if (_selectedItem != null)
{
CoreMethods.PushPageModel<GroupArticlePageModel>(_selectedItem, false, true);
}
}
_selectedItem being the property to which the tapped item is assigned.
Of course you could do it even better and supply the behavior with a CommandParameter in which you put the tapped item reference.

f:form.select does not show me the data

I have an object adherent that contains an object grade(Class: Grade, membres: $uid,$abelGrade). I want to display all grades in database table 'grade'. so I assign a grades (an array of grades) to my view and i write this code :
<f:form.select property="grade" value="{adherent.grade.labelGrade}" options="{grades}" optionValueField="uid" optionLabelField="labelGrade" size="1" id="category" />
but the problem it doesn't display anything. what could be the problem?
The problem could be missing $grade->getUid() and $grade->getLabelGrade() methods. These are called due to the optionValueField and optionLabelField. If thats not the problem, set a breakpoint where you assign the {grades} array to the view and check if it's really an array or an ObjectStorage. Thats everything I can think of right now, maybe you'd like to provide some further code.

autocomplete select listener

I would like to use a method in rich:autocomplete component much the same way like ValueChangeListener, the problem is that I cannot submit the form in order for the Listener to get fired, that's why I wanted to ask you how could I intercept an event in order to execute a Listener in my backing bean. I have tried this:
<rich:autocomplete id="autocompleteOficina"
value="#{agenciaDM.oficinaSeleccionada}" converter="entityConverter"
autocompleteList="#{suggestionEntitiesDM.availableEntitiesList(suggestionEntitiesDM.oficina)}"
var="oficina" fetchValue="#{oficina.label}" showButton="true">
<a4j:ajax event="change" listener="#{oficinaController.empresaSearchSelectedListener}"></a4j:ajax>
<rich:column>
<h:outputText value="#{oficina.label}" />
</rich:column>
</rich:autocomplete>
I have also tried the select event, but no one executed the Listener, why is it not fired?.
Could you please enclose it inside
<h:form></h:form>
Also please check the listener method signature in the backing bean