【发布时间】:2016-10-17 14:32:14
【问题描述】:
我有一个绘图对象 SkiaView。 我在 xaml 文件中创建了许多 SkiaView,因此我正在寻找一种将自定义属性传递给我的 SkiaView 的方法。
我试过这个:
(作者:https://codemilltech.com/back-to-school-adding-a-custom-bindable-property-to-xamarin-forms/)
public static readonly BindableProperty TestVarProperty =
BindableProperty.Create<SkiaView, string>(rv => rv.TestVar,"None",
BindingMode.TwoWay, (bindable,value)=> { return true; },
(bindable, oldValue, newValue) => {
var thisView = (SkiaView)bindable;},
(bindable, oldValue, newValue) => {},
(bindable, value) => {
return value;
}, (bindable) => {
return ">Error<";
});
public string TestVar
{
get { return (string)GetValue(TestVarProperty); }
set { SetValue(TestVarProperty, value); }
}
但这会返回字符串“none”,我想获取并使用我在 xaml 中设置的 TestVar。 因此,如果有人想将属性传递给没有可绑定属性的对象,我会接受。
【问题讨论】:
-
您能否发布代码以显示您分配给
TestVar的内容? -
如果您找到了问题的答案,您应该将其作为答案发布,而不是将其编辑到问题中。
标签: c# visual-studio xaml xamarin xamarin.android