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. 管中窥豹:从Page Performance看Nand Flash可靠性【转】

    转自:https://blog.csdn.net/renice_ssd/article/details/53332746 如果所有的page performace在每次program时都是基本相同的, ...

  2. svn 回退/更新/取消至某个版本命令详解【转】

    转自:http://www.cnblogs.com/mfryf/p/4654110.html 1. 取消Add/Delete 取消文件 svn revert 文件名 取消目录 svn revert - ...

  3. C# sha256 加密算法

    C# 非对称加密 public string sha256(string data) { byte[] bytes = Encoding.UTF8.GetBytes(data); byte[] has ...

  4. 解决getJSON跨域登录Session丢失的问题

    最近在做项目中发现,我用下面的代码异步请求到login.ashx: var memberUrl = rooturl + 'member.ashx?r=' + Math.random() + '& ...

  5. scp拷贝文件报错-bash: scp: command not found

    今天用scp远程传输资料,报错如下: -bash: scp: command not found 在网上搜资料解决办法如下: 安装scp的软件包: # yum install openssh-clie ...

  6. linux:查询软件是否安装以及删除

    参考网址:http://blog.sina.com.cn/s/blog_6d59e57d0102x21u.html 查询java是否安装 rpm -qa |grep java 批量卸载所有带有Java ...

  7. Ibatis.Net 执行存储过程学习(八)

    首先在数据库创建存储过程: create proc [dbo].[usp_GetPersonById] @Id int as begin select Id,Name from Person wher ...

  8. HDR 视频编码

    前转换以及后转换:-f xxx.cfg (以及注意工作目录以及路径名/和//) HEVC视频编码:-c xxx.cfg  -c xx.cfg(视频的配置文件)

  9. mysql的完整卸载

    一.卸载MySQL数据库 1.检查mysql服务并关闭服务进程 (1)登录Linux后执行service mysqld status 或者service mysql status命令查看MySQL服务 ...

  10. Luogu P1318 积水面积

    题目描述 一组正整数,分别表示由正方体迭起的柱子的高度.若某高度值为x,表示由x个正立方的方块迭起(如下图,0<=x<=5000).找出所有可能积水的地方(图中蓝色部分),统计它们可能积水 ...