Xamarin Form Animation - xamarin

I have a simple code that uses ScaleTo method to build a simple animation and the code was working fine up to last Friday and all of the sudden it's not working any more.
Here is my XAML file:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="TestAnim.MainPage">
<StackLayout Orientation="Vertical">
<Image Source="discount.png" x:Name="img" Scale="0.1"/>
<Button Text="Do" Clicked="doIt"/>
</StackLayout>
</ContentPage>
And here is my C# code:
using System;
using System.ComponentModel;
using Xamarin.Forms;
namespace TestAnim
{
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
async void doIt (object sender , EventArgs ev)
{
await img.ScaleTo(1, 2000, Easing.BounceOut);
await img.ScaleTo(0.1, 3000, Easing.BounceIn);
}
}
}
When I run the code, I see no effects at all, if I comment the 2nd ScaleTo call I see my image scales to 1 but this happens immediately instead of within 2 seconds! As result when I have the 2nd scale really the end result is no see no animation at all.
This was working fine before as I mentioned but for some reason the duration seems to be ignored and the scaling seems to happen instantly which is the issue here.
Any one else see the same problem?

If you are using Xamarin.Forms version 4.2+ there is currently a bug about Animations, you can track it here.
I've reproduced your code in Xamarin.Forms 4.1.0.581479 and it is working just fine.

Related

Xamarin.Forms ViewCell / Visual Studio 2019 - "Partial declarations of 'someType' must not specify different base classes"

In my Xamarin.Forms project I am attempting to create a reusable ViewCell. I can't figure out, though, why when I simply create a ViewCell XAML and CS file using the VS-supplied template, it will not compile due to the following error:
"Partial declarations of 'DateViewCell' must not specify different base classes"
This error pops the second I create the file (as you'll see in the code below, I haven't added any code yet and this is all boilerplate) and I have a fully functional Xamarin.Forms project that compiles with no issues if I remove the extension.
DateViewCell.xaml:
<?xml version="1.0" encoding="UTF-8"?>
<ViewCell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="HelloWorld.Extensions.DateViewCell">
<ViewCell.View>
<StackLayout>
<Label Text="Hello Xamarin.Forms!" />
</StackLayout>
</ViewCell.View>
</ViewCell>
DateViewCell.xaml.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace HelloWorld.Extensions
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class DateViewCell : ViewCell
{
public DateViewCell()
{
InitializeComponent();
}
}
}
DateViewCell.xaml.g.cs:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
[assembly: global::Xamarin.Forms.Xaml.XamlResourceIdAttribute("HelloWorld.Extensions.DateViewCell.xaml", "Extensions/DateViewCell.xaml", typeof(global::HelloWorld.Extensions.DateViewCell))]
namespace HelloWorld.Extensions {
[global::Xamarin.Forms.Xaml.XamlFilePathAttribute("Extensions\\DateViewCell.xaml")]
public partial class DateViewCell : global::Xamarin.Forms.ViewCell {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "2.0.0.0")]
private void InitializeComponent() {
global::Xamarin.Forms.Xaml.Extensions.LoadFromXaml(this, typeof(DateViewCell));
}
}
}
Sort of at a dead end here. I tried creating this "DateViewCell" extension manually and I get the same error that I did when I let VS create the file for me. I'm starting to wonder if this is a bug in Xamarin.
Anyone have any suggestions? The SO articles I could find that referenced this particular error didn't really apply and I'm out of ideas on better ways to search this... Thanks everybody.

CustomRenderer not applying

The BackgroundColor property on Xamarin.Forms.Buttons started coloring the entire area assigned to the button instead of just the button, so I started delving into the Custom Renderers in Android to see if I could fix it. The following is the class I created, the .xaml where I use a custom button, and the renderer (it's just supposed to color the button green as a test):
using Xamarin.Forms;
namespace wcsmobile
{
public class wcsButton : Button
{
}
}
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:wcsmobile;assembly=wcsmobile"
x:Class="wcsmobile.Transfer"
Title="Transfer">
<ContentPage.Content>
<StackLayout HorizontalOptions="FillAndExpand">
<local:wcsButton Text="OK" HorizontalOptions="Center"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
[assembly: ExportRenderer(typeof(wcsButton), typeof(ButtonRenderer))]
namespace wcsmobile.Droid
{
class wcsButtonRenderer : ButtonRenderer
{
public wcsButtonRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.SetBackgroundColor(global::Android.Graphics.Color.LightGreen);
}
}
}
}
There is no error, but the button stays gray, not green. Putting a breakpoint at the "base.OnElementChanged(e)" doesn't do anything; the breakpoint never gets hit. Both projects are using Xamarin.Forms version 3.1.0.583944.
Anyone with a clue as to why the Custom Renderer doesn't seem to be applying would be very helpful. (Or even an idea as to why BackgroundColor seemed to stop working in the first place).
As you mentioned "both projects" the answer seems obvious: the renderer from project A isn't applied to project B. You have the choice to move it to appropriate project OR move it to a shared project https://learn.microsoft.com/en-us/xamarin/cross-platform/app-fundamentals/shared-projects?tabs=vswin

how to remove multiple back button from navigation in xamarin?

please help me to sort out following issue.
this is my issue.if push without animation(false)then issue.if animation true then working fine.
// await Navigation.PushAsync<DeleteDealsAndOffersViewModel>(); --> **working fine**
// await Navigation.PushAsync(new DeleteDealsAndOffersViewModel());**working fine**
vm = new DeleteDealsAndOffersViewModel
{
DealsAndOffersList = dealLists,
//CategoryColor = CategoryColor,
IsDelete = true
};
//await Navigation.PushAsync(vm,false); **issue with back button**
I have used following code for back button.this is my base class.
<?xml version="1.0" encoding="UTF-8"?>
<v:ExtendedContentPage
xmlns:v="clr-namespace:Core.Views;assembly=Core"
xmlns="http://xamarin.com/schemas/2014/forms"
LeftBarButtonTitle="< Back"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Vi.Views.BasicV">
<ContentPage.Content>
</ContentPage.Content>
</v:ExtendedContentPage>
now I create another page and set base class on that page
DeleteDealsAndOffersListPage.xaml
<?xml version="1.0" encoding="UTF-8"?>
<view:BasicV
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:view="clr-namespace:Vi.Views;assembly=FlagSpree"
xmlns:sty="clr-namespace:VillageVesl.Styles;assembly=FlagSpree"
xmlns:v="clr-namespace:Core.Views;assembly=Core"
xmlns:comp="clr-namespace:VillageVesl.Views.Components;assembly=FlagSpree"
x:Name="main" Title="{Binding Title}"
LeftBarButtonTitle="Cancel"
BackgroundColor="{x:Static sty:Colors.BGColor}"
x:Class="Vi.Views.DeleteDealsAndOffersListPage">
<ContentPage.ToolbarItems>
<ToolbarItem IsDestructive="true" Text="Delete" Command="{Binding DeleteAllSelectedDealsCommand}" />
</ContentPage.ToolbarItems>
<ContentPage.Content>
</ContentPage.Content>
</view:BasicV>
"DeleteDealsAndOffersListPage.xaml.cs".
namespace Vi.Views
{
public partial class DeleteDealsAndOffersListPage : BasicV
{
public DeleteDealsAndOffersListPage()
{
InitializeComponent();
}
}
}
Now problem is that when I push on DeleteDealsAndOffersListPage then display two back button.
It looks like you are creating your own Back Button. Xamarin will add it's own back button to any page that you push onto a Navigation stack, is that the extra back button you are seeing? If so, before you do the push, add:
NavigationPage.SetHasBackButton(vm, false);

Wrapping an MPVolumeView inside 2 Stack Layouts (Xamarin.IOS)

I am creating a control based on a generic View that works with a custom renderer based on an iOS MPVolumeView, which is the simple control that allows you to select an alternate output route for audio in your app (i.e. Bluetooth Speaker). The code works just fine if I wrap inside a single stack layout, but not if it's inside two stack layouts. My XAML looks like this... very basic:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="DABApp.DabTestPage" xmlns:local="clr-namespace:DABApp;assembly=DABApp">
<ContentPage.Content>
<StackLayout VerticalOptions="CenterAndExpand" HorizontalOptions="FillAndExpand" BackgroundColor="Red">
<StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand" VerticalOptions="FillAndExpand">
<local:AudioOutputView />
</StackLayout>
</StackLayout>
</ContentPage.Content>
</ContentPage>
And here's the guts of my custom renderer:
[assembly: ExportRenderer(typeof(AudioOutputView), typeof(iosAudioOutputViewRenderer))]
namespace DABApp.iOS
{
public class iosAudioOutputViewRenderer: ViewRenderer<AudioOutputView, UIView>
{
MPVolumeView view;
protected override void OnElementChanged(ElementChangedEventArgs<AudioOutputView> e)
{
base.OnElementChanged(e);
if (Control == null)
{
view = new MPVolumeView()
{
ShowsRouteButton = true,
ShowsVolumeSlider = false,
};
SetNativeControl(view);
}
}
}
}
With this XAML and code, when I push the page onto the nav stack async, the page won't even show. If I remove one of the StackLayouts, it works fine.
I changed my IOS control in the CustomRenderer to a simple UILabel and this works fine... so it looks like it has something to do with putting the MPVolumeView inside 2 StackLayouts. I need to be able to do this because of the layout requirements of my app, and it doesn't make any sense why 1 StackLayout is fine, but 2 isn't, and only for this native control.
Any ideas?

Xamarin Forms Signature Pad

Can someone please guide me on how to use a signature pad on xamarin FORMS.
I have tried resources available online, but the dont work in my project.
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:acr="clr-namespace:Acr.XamForms.SignaturePad;assembly=Acr.XamForms.SignaturePad" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Checkin.Signature">
<ContentPage.Content>
<ScrollView>
<StackLayout>
<acr:SignaturePadView
x:Name="padView"
HeightRequest="320"
WidthRequest="240"
BackgroundColor="White"
CaptionText="Caption This"
CaptionTextColor="Black"
ClearText="Clear Me!"
ClearTextColor="Red"
PromptText="Prompt Here"
PromptTextColor="Red"
SignatureLineColor="Aqua"
StrokeColor="Black"
StrokeWidth="2"
/>
</StackLayout>
</ScrollView>
</ContentPage.Content>
Above is one of the codes I have used. A signature pad appears but doesent display anything when I draw on top of it.
This is how the Red Signature pad appears
try to install it on droid project too. that works for me
In the AppDelegate, paste the following code:
public static Type dummyt = typeof(SignaturePad.Forms.iOS.SignaturePadRenderer);
As shown below:
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
public static Type dummyt = typeof(SignaturePad.Forms.iOS.SignaturePadRenderer);
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
The problem apparently is that some DLLs are not

Resources