Xaml 在F中的自定义控件上创建Xamarin.Forms BindableProperty#
我有F#+Xamarin.Forms在工作,没有实际使用的C。它工作正常,但现在我正在尝试在我正在创建的控件上创建BindableProperty。它是可以工作的,但是当我试图用XAML和{DynamicResource blah}绑定到它,或者用某种风格绑定到它时,它就崩溃了 两种工作模式:Xaml 在F中的自定义控件上创建Xamarin.Forms BindableProperty#,xaml,xamarin,f#,xamarin.forms,Xaml,Xamarin,F#,Xamarin.forms,我有F#+Xamarin.Forms在工作,没有实际使用的C。它工作正常,但现在我正在尝试在我正在创建的控件上创建BindableProperty。它是可以工作的,但是当我试图用XAML和{DynamicResource blah}绑定到它,或者用某种风格绑定到它时,它就崩溃了 两种工作模式: <dashboard:ProgressRing DotOnColor="#00d4c3" DotOffColor="#120a22" /> <dashboard:ProgressRing
<dashboard:ProgressRing DotOnColor="#00d4c3" DotOffColor="#120a22" />
<dashboard:ProgressRing DotOnColor="{StaticResource dotOnColor}" DotOffColor="{StaticResource dotOffColor}" />
不工作:
<dashboard:ProgressRing DotOnColor="{DynamicResource dotOnColor}" DotOffColor="{DynamicResource dotOffColor}" />
错误:
Xamarin.Forms.Xaml.XamlParseException:位置18:29。无法分配属性“DotOnColor”:属性不存在,或不可分配,或值和属性之间的类型不匹配
XAML:
Xamarin.Forms肯定在寻找一个字段-我在中找到了以下内容:
我想我会尝试修复它来处理公共静态属性。在我这样做之后,有关于如何提交的提示吗
<?xml version="1.0" encoding="UTF-8"?>
<ContentView
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Dashboard.ProgressRing"
x:Name="view">
<AbsoluteLayout x:Name="absLayout">
<!-- Dots are controlled in the code behind -->
</AbsoluteLayout>
</ContentView>
namespace Dashboard
open System
open Xamarin.Forms
open Xamarin.Forms.Xaml
type ProgressRing() =
inherit ContentView()
do base.LoadFromXaml(typeof<ProgressRing>) |> ignore
let absLayout = base.FindByName<AbsoluteLayout>("absLayout")
static let dotOffColorProperty = BindableProperty.Create("DotOffColor", typeof<Color>, typeof<ProgressRing>, Color.Default)
static let dotOnColorProperty = BindableProperty.Create("DotOnColor", typeof<Color>, typeof<ProgressRing>, Color.Accent)
static member DotOffColorProperty = dotOffColorProperty
static member DotOnColorProperty = dotOnColorProperty
member this.DotOffColor
with get () = this.GetValue dotOffColorProperty :?> Color
and set (value:Color) =
this.SetValue(dotOffColorProperty, value)
member this.DotOnColor
with get () = this.GetValue dotOnColorProperty :?> Color
and set (value:Color) =
this.SetValue(dotOnColorProperty, value)
static BindableProperty GetBindableProperty(Type elementType, string localName, IXmlLineInfo lineInfo,
bool throwOnError = false)
{
var bindableFieldInfo =
elementType.GetFields().FirstOrDefault(fi => fi.Name == localName + "Property" && fi.IsStatic && fi.IsPublic);
Exception exception = null;
if (exception == null && bindableFieldInfo == null) {
exception =
new XamlParseException(
string.Format("BindableProperty {0} not found on {1}", localName + "Property", elementType.Name), lineInfo);
}
if (exception == null)
return bindableFieldInfo.GetValue(null) as BindableProperty;
if (throwOnError)
throw exception;
return null;
}