XAML / Self binding, bindingcontext
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的更多相关文章
- WPF在XAML中Binding使用StringFormat属性
1. 绑定Currency, 如果没有字符的话, =后面需要先加入{}. 不加的话会出问题. 1 <TextBlock Text="{Binding Amount, StringFor ...
- TypeLoadException: 找不到 Windows 运行时类型“Windows.UI.Xaml.Controls.Binding
奇怪的问题,我以为是我不小心添加了什么标签导致的,后来发现...坑爹,把项目名字改一下,然后移除掉,接着再加载一下就可以了.......崩溃了,,,,事实证明==>这个时候再把名字改回去也是不报 ...
- [XAML]类似WPF绑定的Binding的读取方法
在WPF的XAML里,依赖属性可以使用基于BindingBase之类的MarkupExtensin 读取XAML时,会自动的把该BindingBase转换为BindingExpressionBase ...
- WPF入门教程系列(二) 深入剖析WPF Binding的使用方法
WPF入门教程系列(二) 深入剖析WPF Binding的使用方法 同一个对象(特指System.Windows.DependencyObject的子类)的同一种属性(特指DependencyProp ...
- 用XAML做网页!!—终结篇
原文:用XAML做网页!!-终结篇 迄今为止的设计都很顺利,但这次就不得不接触我前面所说的非常糟糕的流文档了,但在此之前先来把标题弄好: <Border BorderBrush="#6 ...
- WPF 的内部世界(Binding)
目录 一.控件与布局 二.Binding基础 前言 "一桥飞架南北, 天堑变通途" 写于1956年,1957年武汉长江大桥建成, 称之为:一桥飞架南北,大堑变通途.它形象地描述武汉 ...
- Xamarin.Forms 现已开启对 UWP 的支持
Xamarin.Forms 现已升级到 2.0.0.6482 , 正式开启了对 UWP 的支持. 要创建 UWP 项目, 必须是 VS2015, WIN8.1 下也可以, 但是只有 Windows 1 ...
- MvvmCross[翻译] 使用Xamarin与MvvmCross完成一个跨平台App
总览 原文:https://github.com/MvvmCross/MvvmCross/wiki/Tip-Calc-A-first-app 我们所做的第一个Model-View-ViewModel( ...
- C#使用Xamarin开发可移植移动应用(3.进阶篇MVVM双向绑定和命令绑定)附源码
前言 系列目录 C#使用Xamarin开发可移植移动应用目录 源码地址:https://github.com/l2999019/DemoApp 可以Star一下,随意 - - 说点什么.. 嗯..前面 ...
随机推荐
- 【腾讯云】自己搭建的腾讯云服务器JavaEE环境
0.安装SSH登录 1.生成公钥对 ssh-keygen -t rsa -P '' -P表示密码,-P '' 就表示空密码,也可以不用-P参数,这样就要三车回车,用-P就一次回车.它在/home/ch ...
- 【API】文件操作编程基础-CreateFile、WriteFile、SetFilePointer
1.说明 很多黑客工具的实现是通过对文件进行读写操作的,而文件读写操作实质也是对API函数的调用. 2.相关函数 CreateFile : 创建或打开文件或I/O设备.最常用的I/O设备如下:文件,文 ...
- Kafka入门经典教程【转】
问题导读 1.Kafka独特设计在什么地方?2.Kafka如何搭建及创建topic.发送消息.消费消息?3.如何书写Kafka程序?4.数据传输的事务定义有哪三种?5.Kafka判断一个节点是否活着有 ...
- 解决windows10 里vs2017 直接开始执行提示“此任务要求应用程序有提升的权限”1.
1.打开vs的安装路径,我的是 C:\Program Files (x86)\Common Files\Microsoft Shared\MSEnv\ ,找到 VSLauncher.exe 右击该文 ...
- MongoDB 3.x 安装及权限验证
1.首先在网上下载MongoDB的安装包,我这边使用的是3.2版本: 2.安装MongoDB安装程序,安装完成后设置环境变量,我这边的安装路径是:“C:\Program Files\MongoDB\S ...
- 关于spring中Assert的应用(方法入参检测工具类)
关于spring中Assert的应用(方法入参检测工具类) Web 应用在接受表单提交的数据后都需要对其进行合法性检查,如果表单数据不合法,请求将被驳回.类似的,当我们在编写类的方法时,也常常需要对方 ...
- 破解验证码模拟登陆cnblogs
from selenium import webdriver from selenium.webdriver import ActionChains from PIL import Image imp ...
- ftp配置文件
vsftpd配置文件采用“#”作为注释符,以“#”开头的行和空白行在解析时将被忽略,其余的行被视为配置命令行,每个配置命令的“=”两边不要留有空格.对于每个配置命令,在配置文件中还列出了相关的配置说明 ...
- spirngboot 注解方式注入自定义参数
在代码中 @value("oracle.user") private String user; 在配置文件中 oracle.user=root
- Eclipse 的一些调试技巧(转)
原文:http://blog.csdn.net/manymore13/article/details/8972602 1.条件断点 如果你不知道如何添加断点,只需点击左边面板(行号前面)断点即被创建. ...