davidbritch / behaviors Goto Github PK
View Code? Open in Web Editor NEWBehaviors for Xamarin.Forms
License: MIT License
Behaviors for Xamarin.Forms
License: MIT License
Reference to the PCL published over NuGET repostory is not working on iOS. The app gives me the following error at runtime:
System.IO.FileNotFoundException: Could not load file or assembly 'Behaviors' or one of its dependencies
The Windows Universal and Android apps works well.
Hi there, i have this code:
<Image Source="{Binding FavoriteIcon,Mode=TwoWay}"> <Image.GestureRecognizers> <TapGestureRecognizer Command="{Binding CommmandSetFavorite}"/> </Image.GestureRecognizers> </Image>
I would like that when touch it this'll make an animation of ScaleAction through GestureRecognizers, how could i do it?
Hello and thanks for your great work. We are starting to use your package but won't be able to use it with already given RelayCommands from the existing viewmodels using the mvvm light framework. Is there a chance to get these two to work together, or do we have to map an ICommand to the RelayCommand in at logic level (viewmodel)? AFAIK, the mvvm light RelayCommand implements the ICommand.
When I use the ListViewSelected-Event with the ICommand (as stated in your samples), everything works fine. Bound to the RelayCommand, nothing gets fired/executed, not even breakpoints are being hitten.
Env: Xamarin Forms 3.2, Android/iOS-Projects, MVVMLight, .net standard 2.0, behaviors 1.4
Many thanks in advance.
Hi @davidbritch
I have this code
InvokeCommandAction icsSelectedItem = new InvokeCommandAction();
icsSelectedItem.SetBinding(InvokeCommandAction.CommandProperty, "ItemSelectedCommand");
EventHandlerBehavior ehbSelectedItem = new EventHandlerBehavior() { EventName = "ItemSelected" };
ehbSelectedItem.Actions.Add(icsSelectedItem);
It works fine.
But I would like to use ItemTapped event, not ItemSelected. If I change EventName to ItemTapped, It does not work...
Hello David,
The AnimationDemoPage throws an exception when clicking on the button during animation:
System.InvalidOperationException: An attempt was made to transition a task to a final state when it had already completed.
I found how to inactivate the button during the animation:
<Button.Behaviors>
<behaviors:EventHandlerBehavior EventName="Clicked">
<behaviors:SetPropertyAction TargetObject="{x:Reference runAnimationButton}"
PropertyName="IsEnabled" Value="false" />
<behaviors:SetPropertyAction
TargetObject="{x:Reference stopAnimationButton}"
PropertyName="IsEnabled"
Value="true" />
<behaviors:SetPropertyAction
TargetObject="{x:Reference stopAnimationButton}"
PropertyName="IsVisible"
Value="true" />
...
<behaviors:SetPropertyAction
TargetObject="{x:Reference runAnimationButton}"
PropertyName="IsEnabled" Value="true" />
<behaviors:SetPropertyAction
TargetObject="{x:Reference stopAnimationButton}"
PropertyName="IsEnabled"
Value="false" />
But I did not find how to cancel the animation by clicking on the "Stop animation" button.
Here what I tried out:
Above code for stopAnimationButton plus:
<Button x:Name="stopAnimationButton" Text="Stop animation (ineffective)" IsVisible="true" IsEnabled="false">
<Button.Behaviors>
<behaviors:EventHandlerBehavior EventName="Clicked">
<behaviors:InvokeMethodAction TargetObject="{x:Reference animationPage}" MethodName="OnStopAnimation" />
<behaviors:SetPropertyAction TargetObject="{x:Reference runAnimationButton}" PropertyName="IsEnabled" Value="true" />
</behaviors:EventHandlerBehavior>
</Button.Behaviors>
</Button>
public void OnStopAnimation(object sender, EventArgs args)
{
//KO no animation.Commit(.., "animationID", ...) defined: this.AbortAnimation("animationID";
//KO still same runtime exception: ViewExtensions.**CancelAnimations**(image);
ViewExtensions.**CancelAnimations**(this); //KO: no effect (but no exception neither)
}
Any idea?
Thanks.
Best regards,
Nikolas
i got this error on iOS platform only, does iOS need to something special to work ? It seems like the method "EventToCommandBehavior" can not be found in namespace. It's working on android platform.
Hello !
I have declared in many pages something like this:
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="xxx.Views.SplashPage"
xmlns:behaviors="clr-namespace:Behaviors;assembly=Behaviors"
xmlns:viewModelBase="clr-namespace:xxx.ViewModels.Base;assembly=xxx"
xmlns:markupExtensions="clr-namespace:xxx.ComponentModel.MarkupExtensions;assembly=xxx.forms"
viewModelBase:ViewModelLocator.AutoWireViewModel="true">
<!-- PAGE BEHAVIORS -->
<ContentPage.Behaviors>
<behaviors:EventHandlerBehavior
EventName="Appearing">
<behaviors:ActionCollection>
<behaviors:InvokeCommandAction
Command="{Binding Command}"
CommandParameter="{x:Reference Image}" />
</behaviors:ActionCollection>
</behaviors:EventHandlerBehavior>
</ContentPage.Behaviors>
<!-- PAGE CONTENT -->
<ContentPage.Content>
When I compile in debug I can run the application physically or in the simulator, but when I compile in Release and when I navigate to a page that contains some behavior, my application suddenly crashes and I get:
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
Im using :
Xamarin.Mac
Version: 4.4.1.193 (Visual Studio Community)
Xamarin.iOS
Version: 11.12.0.4 (Visual Studio Community)
Xamarin.Forms
Version: 3.0.0.482510
Behaviors.Forms
Version: 1.4.0
Any Ideas? I've tried to remove the action collection tag or removing the command and CommandParameter with no success.
Thank you!
Bug: Using ListView's ItemSelected
event with InvokeCommandAction
& passing selected item using CommandParameter
passes previously selected item (instead of currently selected item).
Note: Passing selected item using Converter
works fine.
I am attempting to upgrade an existing Xamarin project to the latest versions of various libraries. The Xamarin forms themselves live in a shared .NET Standard library. My page has a ListView on it & I am attempting to capture the event fired when an item is 'chosen'. However, the ICommand in my ViewModel is not executing.
Could you (@davidbritch) possibly take a look at my StackOverflow Question on this?
NOTES:
Hi there, I trying to the SelectedItemChangedArgs on the SelectedItemChanged event but not entirely sure how to get the EventArgs, do I need to use a converter or is it passed into a parameter I can use?
<controls:Dropdown.Behaviors>
<behaviors:EventHandlerBehavior EventName="SelectedItemChanged">
<behaviors:InvokeCommandAction Command="{Binding SelectedItemChangedCommand}" CommandParameter="{Binding ??}" />
</behaviors:EventHandlerBehavior>
</controls:Dropdown.Behaviors>
This is what I would like to do in the viewModel:
public Command<SelectedItemChangedArgs> SelectedItemChanged
{
get
{
return new Command<SelectedItemChangedArgs>(async (selectedItemChangedArgs) =>
{
});
}
}
How can I retrieve the EventArgs in the command??
Awesome tool David.
When i upgrade to XF 3.5, the following crashed Android now when an item is tapped.
```
<ListView
x:Name="ListView"
IsVisible="{Binding Items, Converter={StaticResource EmptyListIsFalseConverter}}"
AbsoluteLayout.LayoutFlags="XProportional,SizeProportional"
AbsoluteLayout.LayoutBounds="0,45,1,1"
android:ListView.IsFastScrollEnabled="True"
ItemsSource="{ Binding Items }"
CachingStrategy="RecycleElement"
HasUnevenRows="True"
RefreshCommand="{Binding RefreshCommand}"
IsRefreshing="{Binding IsBusy}"
IsPullToRefreshEnabled="true">
<ListView.Behaviors>
<behaviors:EventHandlerBehavior EventName="ItemTapped">
<behaviors:InvokeCommandAction Command="{Binding ItemTappedCommand}" />
</behaviors:EventHandlerBehavior>
</ListView.Behaviors>
<ListView.ItemTemplate>
<DataTemplate x:DataType="{x:Type addressBook:AddressBookItem}">
<ViewCell>
<template:AddressBookCell />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
<!-- Prevents ListView from hiding end under the Tab it's embedded in -->
<ListView.Footer>
<StackLayout HeightRequest="50"></StackLayout>
</ListView.Footer>
</ListView>
Hi @davidbritch
I have a Switch inside a ListView.
I would like to use EventHandlerBehavior with Toggled event, but I think I miss something:
<Switch Grid.Row="2"
Grid.Column="1"
WidthRequest="100"
HorizontalOptions="End"
VerticalOptions="End"
OnColor="{StaticResource Prada.ButtonForeground}"
IsToggled="{Binding IsOk, Mode=TwoWay}" >
<Switch.Behaviors>
<behaviors:EventHandlerBehavior EventName="Toggled">
<behaviors:InvokeCommandAction Command="{Binding ToggledCommand}"/>
</behaviors:EventHandlerBehavior>
</Switch.Behaviors>
</Switch>
can you help me?
Thanks
Hi,
I've been using Behaviors without a problem until Xamarin.Forms v3.0.
When I updated to Xamarin Forms v3.0, I got the below exception
Cannot assign property "Actions": Property does not exist, or is not assignable, or mismatching type between value and property
MyView.xaml
<ContentPage.Behaviors>
<behaviors:EventHandlerBehavior EventName="Appearing">
<behaviors:InvokeCommandAction Command="{Binding PageAppearingCommand}" />
</behaviors:EventHandlerBehavior>
</ContentPage.Behaviors>
MyViewModel.cs
public ICommand PageAppearingCommand => new Command(async () =>
{
await PageAppearingAsync();
});
Hi @davidbritch
I have a Switch inside a ListView.
I would like to use EventHandlerBehavior with Toggled event, but I think I miss something:
<Switch Grid.Row="2"
Grid.Column="1"
WidthRequest="100"
HorizontalOptions="End"
VerticalOptions="End"
OnColor="{StaticResource Prada.ButtonForeground}"
IsToggled="{Binding IsOk, Mode=TwoWay}" >
<Switch.Behaviors>
<behaviors:EventHandlerBehavior EventName="Toggled">
<behaviors:InvokeCommandAction Command="{Binding ToggledCommand}"/>
</behaviors:EventHandlerBehavior>
</Switch.Behaviors>
</Switch>
can you help me?
Thanks
Hello! I recently came accros this awesome library and wanted to give it a try. However, when I try to use DataChangedBehavior and InvokeCommandAction I am getting the above-mentioned error. I have copied the use of the library from your sample code in the repo:
<StackLayout>
<Label Text="Invoke Command when Data Changes" FontAttributes="Bold" HorizontalOptions="Center" />
<Entry x:Name="entry" Placeholder="Enter Xamarin here">
<Entry.Behaviors>
<behaviors:DataChangedBehavior Binding="{Binding Path=Text, Source={x:Reference entry}}"
ComparisonCondition="Equal" Value="Xamarin">
<behaviors:InvokeCommandAction Command="{Binding OutputMessageCommand}"
CommandParameter="{Binding Path=Text, Source={x:Reference entry}}" />
</behaviors:DataChangedBehavior>
</Entry.Behaviors>
</Entry>
<Label Text="{Binding MessageText}" />
</StackLayout>
Hi @davidbritch . Is this package compatible with NS2.0?
Using the NuGet package v1.1.0 and don't use [assembly: XamlCompilation(XamlCompilationOptions.Compile)] the behaviors doesn't work.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Xamarin.Forms.Xaml.XamlParseException: Position 11:8. Type behaviors:InvokeCommandAction not found in xmlns clr-namespace:Behaviors;assembly=Behaviors
at Xamarin.Forms.Xaml.CreateValuesVisitor.Visit(ElementNode node, INode parentNode)
at Xamarin.Forms.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
at Xamarin.Forms.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode
the link to nuget package is mismatch, it is target to 1.3 version instead of 1.4. Thks
Hi David,
I install your Behaviors for Xamarin.Forms 1.1.0 from Nuget.
When I publish my UWP app to Windows App Store, then got an error message:
Error Found: The debug configuration test detected the following errors:
The binary Behaviors.dll is built in debug mode.
So, I use dotPeek to check the Behaviors.dll properties, in Pdb File property:
y:\Repos\behaviors\Library\Behaviors\obj\Debug\Behaviors.pdb
Maybe you upload the debug mode dll to Nuget not release?
Thank you, and Sorry for my poor English.
Yute Lin
Can you add EventArgsConverter like prism library ?
Hi @davidbritch
I have updated your Package to 1.4.0 and when I run the app to a real Device (Android 4.4)
I have this error
Unhandled Exception:
System.TypeLoadException: Could not resolve type with token 010000cc (from typeref, class/assembly Behaviors.BehaviorPropertiesBase, Behaviors, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null).
Returnig to 1.3.0 all works fine
Alessandro
Hi,
I recently switched from shared project to PCL library.
Using the shared project, everything works great, but in the PCL project I get the message (XamlParseException), that the FadeAction type can't be found.
Do you have any suggestions?
Hello
I have the xaml below which compiles fine but shows a weird error on InvokeCommandAction when designing the xaml. This is happening in XF3.6
<behaviors:EventHandlerBehavior EventName="SlidedToIndex"> <behaviors:InvokeCommandAction Command="{Binding DaySelectedCommand}"/> </behaviors:EventHandlerBehavior>
With error: Property 'Actions' does not support values of type 'InvokeCommandAction'.
Hello @davidbritch and thanks for this wonderful repo!
In my scenario I have a ViewModel that wants to signal the View to do a one-time action (animation etc.).
Does this library offer anything that can achieve that?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.