【发布时间】:2021-01-21 15:34:33
【问题描述】:
我正在 Xamarin Forms MacOS 中创建自定义框架。框架本身看起来不错,但想法是在被选中时淡入。我创建了一个可以成功运行的可绑定属性,并且 TranslateBox 方法运行良好。
问题是await this.FadeTo(1, 1250, Easing.Linear);。没有动画发生,而是在 1250 秒后出现。
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);
}
});
}
}
任何线索是什么导致了这个问题?这是一个已知的错误吗?如果是,是否有任何解决方法/黑客?
【问题讨论】:
标签: c# macos xamarin xamarin.forms