Reputation: 401
I am creating a custom frame in Xamarin Forms MacOS. The frame itself looks good, but the idea is for it to fade in when it is getting selected. I have created a bindableproperty that works successfully and the TranslateBox
method runs just fine.
The issue is await this.FadeTo(1, 1250, Easing.Linear);
. No animation is happening, instead after 1250 seconds it shows up.
public class CustomFrame : Frame
{
public bool IsExpanded
{
get { return (bool)GetValue(IsExpandedProperty); }
set { SetValue(IsExpandedProperty, value); }
}
public static readonly BindableProperty IsExpandedProperty = BindableProperty.Create(
nameof(IsExpanded),
typeof(bool),
typeof(CustomFrame),
false,
propertyChanged: IsExpandedChanged
);
private static void IsExpandedChanged(BindableObject bindable, object oldVal, object newVal)
{
var getInstance = (CustomFrame)bindable;
getInstance.TranslateBox();
}
public void TranslateBox()
{
Device.BeginInvokeOnMainThread(async () =>
{
if (this.IsExpanded)
{
await this.FadeTo(1, 1250, Easing.Linear);
}
else
{
await this.FadeTo(0, 1250, Easing.Linear);
}
});
}
}
Any clues what is causing this issue? Is it a known bug, and if so are there any workarounds/hacks out there?
Upvotes: 0
Views: 176
Reputation: 12723
I have tested in local site, it works well.
Testing with two button clicked event to change the IsExpanded
property.
Xaml code:
<local:CustomFrame x:Name="MyFrame" BackgroundColor="#2196F3">
<Lable Text="Welcome to Xamarin.Forms!" FontSize=""36/>
</local:CustomFrame>
<Button Text="Animate" Clicked="Button_Clicked_1"/>
<Button Text="AnimateBack" Clicked="Button_Clicked_2"/>
Xaml.cs code:
void Button_Clicked_1(System.Object sender, System.EventArgs e)
{
MyFrame.IsExpanded = true;
}
void Button_Clicked_2(System.Object sender, System.EventArgs e)
{
MyFrame.IsExpanded = false;
}
Note: The version of Xamarin.Forms is 4.8.0.1451
, if not the latest version you could update it to check.
Upvotes: 1