我正在使用可绑定属性我从xaml文件中收到此错误
在类型“FadableImageControl”中找不到属性“FadePropertyOf.”
这看起来像是一个强制转换问题,但是我还没有找到一种方法来使我对象读取此属性ImageFadeProperty,ImageSourceOf工作正常。有人知道我遗漏了什么吗?
public partial class FadableImageControl : ContentView
{
public static readonly BindableProperty ImageSourceProperty =
BindableProperty.Create("ImageSourceOf",
typeof(ImageSource), typeof(FadableImageControl));
public ImageSource ImageSourceOf
{
get { return GetValue(ImageSourceProperty) as ImageSource; }
set { SetValue(ImageSourceProperty, value); }
}
public bool FadePropertyOf
{
get => (bool)GetValue(FadePropertyOfProperty);
set => SetValue(FadePropertyOfProperty, value);
}
public static readonly BindableProperty FadePropertyOfProperty =
BindableProperty.Create(
"FadePropertyOf",
typeof(bool),
typeof(FadableImageControl),
defaultValue: false,
defaultBindingMode: BindingMode.TwoWay,
propertyChanged: async(BindableObject bindable, object oldValue, object newValue)=>
{
var myControl = bindable as FadableImageControl;
var o = oldValue;
var n = newValue;
var opacityControl = myControl.fadableImage;
if (opacityControl.Opacity == 0)
{
await opacityControl.FadeTo(1, 100);
}
else
{
await opacityControl.FadeTo(0, 100);
}
});
public FadableImageControl()
{
InitializeComponent();
}
}
还在XAML中添加了以下内容:
<?xml version="1.0" encoding="UTF-8" ?>
<ContentPage
x:Class="animations.Views.MyPageInitComp"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:bindables="clr-namespace:animations.Views.Bindables">
<ContentPage.Content>
<StackLayout Padding="20" BackgroundColor="Pink">
<StackLayout Padding="20" BackgroundColor="DeepPink">
<bindables:FadableImageControl FadePropertyOfProperty="" ImageSourceOf="ino.png" Opacity="0" />
</StackLayout>
</StackLayout>
</ContentPage.Content>
1条答案
按热度按时间eblbsuwk1#
下面的代码对我很有效(我假设
FadableImageControl
是ContentView
):第一个