Hello,

I want to bind the text property of a editor element to BindableProperty. Here is what I tried:

MyForm.xaml

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage x:Class="Com.Acme.MyForm"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:local="clr-namespace:Com.Acme;assembly=Com.Acme"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
> <ContentPage.Content>
<Grid>
<Label Text="1" />
<Editor BindingContext="{local:MyForm}" Grid.Column="1" Text="{Binding Path=MyProperty}" />
</Grid>
</ContentPage.Content>
</ContentPage>

MyForm.cs

namespace Com.Acme {

public partial class MyForm : ContentPage {

    public static readonly BindableProperty MyPropertyProperty = BindableProperty.Create(
"MyProperty",
typeof(Object),
typeof(MyForm),
null,
BindingMode.TwoWay,
null,
null,
null,
null,
null
); public MyForm () {
InitializeComponent ();
} public Object MyProperty { get { return GetValue (MyPropertyProperty); }
set { SetValue(MyPropertyProperty, value); } } }

While the code above is running, I see around 60 block of this exception (all are different but similar) in Application Output panel and application exits in emulator:

[mono-rt]   at <unknown> <0xffffffff>
[mono-rt] at (wrapper managed-to-native) System.Reflection.MonoCMethod.InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&) <IL 0x0001c, 0xffffffff>
[mono-rt] at System.Reflection.MonoCMethod.InternalInvoke (object,object[]) [0x00002] in /Users/builder/data/lanes/2058/58099c53/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:535
[mono-rt] at System.Activator.CreateInstance (System.Type,bool) [0x000af] in /Users/builder/data/lanes/2058/58099c53/source/mono/mcs/class/corlib/System/Activator.cs:321
[mono-rt] at System.Activator.CreateInstance (System.Type) [0x00000] in /Users/builder/data/lanes/2058/58099c53/source/mono/mcs/class/corlib/System/Activator.cs:214
[mono-rt] at Xamarin.Forms.Xaml.CreateValuesVisitor.Visit (Xamarin.Forms.Xaml.ElementNode,Xamarin.Forms.Xaml.INode) <IL 0x00192, 0x00c57>
[mono-rt] at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor,Xamarin.Forms.Xaml.INode) <IL 0x000b8, 0x006b7>
[mono-rt] at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor,Xamarin.Forms.Xaml.INode) <IL 0x00058, 0x0038e>
[mono-rt] at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor,Xamarin.Forms.Xaml.INode) <IL 0x0008f, 0x00576>

Where am I doing something wrong?

Well... I solved it. I'm writing the solution here.

First, I set the name of content page by x:Name directive and removed imported local namespace:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage x:Class="Com.Acme.MyForm"
x:Name="xMyForm"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
>
...

then I changed BindingContext property as below:

...
<Editor BindingContext="{x:Reference Name=xMyForm}" Grid.Column="1" Text="{Binding Path=MyProperty}" />
...

now MyProperty value appears in the editor.

XAML / Self binding, bindingcontext的更多相关文章

  1. WPF在XAML中Binding使用StringFormat属性

    1. 绑定Currency, 如果没有字符的话, =后面需要先加入{}. 不加的话会出问题. 1 <TextBlock Text="{Binding Amount, StringFor ...

  2. TypeLoadException: 找不到 Windows 运行时类型“Windows.UI.Xaml.Controls.Binding

    奇怪的问题,我以为是我不小心添加了什么标签导致的,后来发现...坑爹,把项目名字改一下,然后移除掉,接着再加载一下就可以了.......崩溃了,,,,事实证明==>这个时候再把名字改回去也是不报 ...

  3. [XAML]类似WPF绑定的Binding的读取方法

    在WPF的XAML里,依赖属性可以使用基于BindingBase之类的MarkupExtensin 读取XAML时,会自动的把该BindingBase转换为BindingExpressionBase ...

  4. WPF入门教程系列(二) 深入剖析WPF Binding的使用方法

    WPF入门教程系列(二) 深入剖析WPF Binding的使用方法 同一个对象(特指System.Windows.DependencyObject的子类)的同一种属性(特指DependencyProp ...

  5. 用XAML做网页!!—终结篇

    原文:用XAML做网页!!-终结篇 迄今为止的设计都很顺利,但这次就不得不接触我前面所说的非常糟糕的流文档了,但在此之前先来把标题弄好: <Border BorderBrush="#6 ...

  6. WPF 的内部世界(Binding)

    目录 一.控件与布局 二.Binding基础 前言 "一桥飞架南北, 天堑变通途" 写于1956年,1957年武汉长江大桥建成, 称之为:一桥飞架南北,大堑变通途.它形象地描述武汉 ...

  7. Xamarin.Forms 现已开启对 UWP 的支持

    Xamarin.Forms 现已升级到 2.0.0.6482 , 正式开启了对 UWP 的支持. 要创建 UWP 项目, 必须是 VS2015, WIN8.1 下也可以, 但是只有 Windows 1 ...

  8. MvvmCross[翻译] 使用Xamarin与MvvmCross完成一个跨平台App

    总览 原文:https://github.com/MvvmCross/MvvmCross/wiki/Tip-Calc-A-first-app 我们所做的第一个Model-View-ViewModel( ...

  9. C#使用Xamarin开发可移植移动应用(3.进阶篇MVVM双向绑定和命令绑定)附源码

    前言 系列目录 C#使用Xamarin开发可移植移动应用目录 源码地址:https://github.com/l2999019/DemoApp 可以Star一下,随意 - - 说点什么.. 嗯..前面 ...

随机推荐

  1. MapReduce--shuffle

    一.Shuffle简介 Shuffle的正常意思是洗牌或弄乱,shuffle的大致范围就是把map task的输出结果有效的传送到Reduce端.也可以这样理解,shuffle描述着数据从map ta ...

  2. 转:VMWare服务器虚拟化--转自CSDN

    http://blog.csdn.net/kkfloat/article/category/1249845/3

  3. malloc 函数详解

    很多学过C的人对malloc都不是很了解,知道使用malloc要加头文件,知道malloc是分配一块连续的内存,知道和free函数是一起用的.但是但是: 一部分人还是将:malloc当作系统所提供的或 ...

  4. casperjs批量执行多个url

    var fs=require("fs"); ////-------sample.js-------// //casperオブジェクトを生成var casper = require( ...

  5. 揭开webRTC媒体服务器的神秘面纱——WebRTC媒体服务器&开源项目介绍

    揭开webRTC媒体服务器的神秘面纱--WebRTC媒体服务器&开源项目介绍 WebRTC生态系统是非常庞大的.当我第一次尝试理解WebRTC时,网络资源之多让人难以置信.本文针对webRTC ...

  6. 点击超链接打开本地QQ

    2014年6月4日 10:20:18 张志斌 这个功能实际上是属于腾讯的推广项目"一键加群"功能: http://qun.qq.com/join.html 用户必须有自己的群,登录 ...

  7. css中width和padding-top实现正方形

    .div{ width: 100%; height: 0; padding-top: 100% } 这个时候,padding-top的值与width相等,所以可以让div宽高一样,值为width的值

  8. webpack2.0学习

    1.进到指定的目录下,新建自己的文件名 mkdir webpack-test 创建你的项目名称或者你己有的项目名称cd webpack-test npm initnpm install webpack ...

  9. mysql 用init-connect+binlog实现用户操作追踪做access的ip的log记录

    在MYSQL中,每个连接都会先执行init-connect,进行连接的初始化.我们可以在这里获取用户的登录名称和thread的ID值.然后配合binlog,就可以追踪到每个操作语句的操作时间,操作人等 ...

  10. java 其它可选方法

    异常处理的一个原则时,只有当你在知道如何处理的情况下才捕获异常,异常处理的一个重要目标时将错误处理代码同错误发生的地点相分离. "被检查异常"强制你在还没准备好处理错误的时候被迫加 ...