Label下FormattedText中的Span无法使用Binding的解决方法
在Xamarin.Forms中,Xaml的模板功能并没有原生WPF丰富,比如Label中虽然有FormattedText可以添加Span来丰富Label的功能,但是下面的Span中的Text并没有绑定属性,无法直接绑定Model的值。
但是FormattedText本身是可以进行绑定的。
那么折中一下,进行数据绑定的时候绑定FormattedText属性,就能临时解决一下问题。
例如有一个Model
using Xamarin.Forms; namespace Baishijiaju.StoreApp.Core.Models
{
public class AvararInfo
{
public string AvararUrl { set; get; } = @"http://192.168.0.228/Common/Images/default-profile-picture.png";
public string Name { set; get; } = "百氏佳居";
public string Company { set; get; } = "哈尔滨市百氏佳居网络科技有限公司";
public FormattedString NameFormattedString
{
get
{
return new FormattedString
{
Spans = {
new Span { Text = "经纪人", ForegroundColor=Color.FromHex("FF6F42"), FontSize= },
new Span { Text = Name,ForegroundColor=Color.FromHex(""), FontSize= } }
};
}
}
}
}
然后我们在进行数据绑定的时候,给Label的FormattedText进行绑定NameFormattedString,Model则正常进行创建就可以了。
<local:AvatarView
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=1,Constant=-228}"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,Property=Y,Factor=0,Constant=12}" >
<local:AvatarView.BindingContext>
<model:AvararInfo />
</local:AvatarView.BindingContext>
</local:AvatarView>
那么我们在Xaml中
<?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="Baishijiaju.StoreApp.Core.Components.AvatarView"
xmlns:effect="clr-namespace:Baishijiaju.StoreApp.Core.Effects" WidthRequest="192" HeightRequest="48">
<ContentView.Content>
<RelativeLayout VerticalOptions="Fill" HorizontalOptions="Fill">
<Label
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=1,Constant=0}"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,Property=Y,Factor=1,Constant=0}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent,Property=Height,Factor=1,Constant=0}">
<BoxView.Effects>
<effect:BorderEffect BorderColor="White" BorderRadius="48" BorderWidth="1" CoverBackgroundColor="True" />
</BoxView.Effects>
</Label>
<Label Text="{Binding Company}" FontSize="12" TextColor="{StaticResource Gery500}" HorizontalTextAlignment="End"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=1,Constant=-48}"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,Property=Y,Factor=0,Constant=8}"/>
<Label FormattedText="{Binding NameFormattedString}" HorizontalTextAlignment="End"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=1,Constant=-48}"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,Property=Y,Factor=0,Constant=26}"/>
<Image Source="{Binding AvararUrl}" WidthRequest="40" HeightRequest="40"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=1,Constant=-44}"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,Property=Y,Factor=0,Constant=4}"/>
</RelativeLayout>
</ContentView.Content>
</ContentView>
Label下FormattedText中的Span无法使用Binding的解决方法的更多相关文章
- html 中设置span的width完美解决方法
在默认情况下,由于span是行标签,设置width是无效的.只有改变display的属性,才可以实现设置宽度. 1.初步想法 span{ background-color:#ccc; display: ...
- Myeclipse开发环境下文件中出现的提示错误与解决方法:The import javax.servlet cannot be resolved?
1.开发工具:MyEclipse 2.右击项目 >> Build Path >> Add External Archives (Tomcat >> li ...
- jquery中checkbox全选失效的解决方法
这篇文章主要介绍了jquery中checkbox全选失效的解决方法,需要的朋友可以参考下 如果你使用jQuery 1.6 ,代码if ( $(elem).attr(“checked”) ),将 ...
- 【配置】检测到在集成的托管管道模式下不适用的ASP.NET设置的解决方法(非简单设置为【经典】模式)。
× 检测到在集成的托管管道模式下不适用的ASP.NET设置的解决方法(非简单设置为[经典]模式). 我们将ASP.NET程序从IIS6移植到IIS7,可能运行提示以下错误: HTTP 错误 5 ...
- Linux中切换用户变成-bash4.1-$的解决方法【转】
转自 Linux中切换用户变成-bash4.1-$的解决方法 - xia_xia的博客 - 博客频道 - CSDN.NEThttp://blog.csdn.net/xia_xia0919/articl ...
- win7下安装Ubuntu后进不去win7的解决方法
win7下安装Ubuntu后进不去win7的解决方法 刚刚给同学在win7下安装了Ubuntu16.04,结果在安装完后竟然无法在电脑重启后,找到win7的进入选项. 在网上找了找,都不行!就差点重装 ...
- Oracle 18c 数据库中scott用户不存在的解决方法
Oracle 18c 数据库中scott用户不存在的解决方法 注:该文为转载 上面标题可直接跳转 原文地址:http://www.cnblogs.com/zangdalei/p/5482732.htm ...
- 记一次SpringBoot 开发中所遇到的坑和解决方法
记一次SpringBoot 开发中所遇到的坑和解决方法 mybatis返回Integer为0,自动转型出现空指针异常 当我们使用Integer去接受数据库中表的数据,如果返回的数据中为0,那么Inte ...
- linux下安装Oracle时交换空间不足的解决方法
摘:linux下安装Oracle时交换空间不足的解决方法 linux上安装Oracle时交换空间不足的解决办法 增加交换空间有两种方法: 严格的说,在系统安装完后只有一种方法可以增加swap,那就是本 ...
随机推荐
- Python 小结
1. Python pass是空语句,是为了保持程序结构的完整性. pass 不做任何事情,一般用做占位语句. 2.删除一个list里面的重复元素 方法一:是利用map的fromkeys来自动过滤重复 ...
- 有关Zedgraph的功能扩展的笔记
1.坐标轴范围.刻度调整后需要加上下面的语句才能刷新: zedGraphControl1.AxisChange(); zedGraphControl1.Refresh(); 2.坐标范 ...
- Embarcadero RAD Studio 2016 Product Approach and Roadmap
delphi 2016 路线图 http://community.embarcadero.com/article/news/16211-embarcadero-rad-studio-2016-pro ...
- 跟我学算法聚类(kmeans)
kmeans是一种无监督的聚类问题,在使用前一般要进行数据标准化, 一般都是使用欧式距离来进行区分,主要是通过迭代质心的位置 来进行分类,直到数据点不发生类别变化就停止, 一次分类别,一次变换质心,就 ...
- Kettle中配置oracle RAC
由于项目中使用了oracle v-ip做了oracle数据库集群,现在需要把项目中程序进行升级. 原来的程序中直接使用的是JDBC然后配置的kettle.properties配置文件,如下图: 根据项 ...
- python实战===python控制键盘鼠标:pynput
Python控制键盘鼠标:pynput 地址:https://pypi.python.org/pypi/pynput 这个库让你可以控制和监控输入设备. 对于每一种输入设备,它包含一个子包来控制和监控 ...
- 重构--去除丑陋的switch语句
最近几天,在进行重构的时候,遇到了一个极其丑陋的代码(自己写的 /捂脸 当时时间紧,于是....),今天去重构的时候无论如何也想不出方法,去除这个丑陋的switch语句 ,于是写篇博客,让自己记住这 ...
- Android5.0新动画之VectorDrawable
SVG是前端的一套标准,Vector是在Android中使用,他只是实现了SVG语言的Path的标签 Vector的常用语法 M = moveto(M X,Y): 将画笔移动到指定的坐标位置 ...
- js引用类型赋值,深拷贝与浅拷贝
JS中引用类型使用等号“=” 赋值,相当于把原来对象的地址拷贝一份给新的对象,这样原来旧的对象与新的对象就指向同一个地址,改变其中一个对象就会影响另外那个对象,也就是所谓的浅拷贝.例如: var ar ...
- JsSIP 注册,拨打填坑
吐个槽: http://tryit.jssip.net/ 这个毛东西,默认是要使用视频的,而且没得设置不使用,至少我没看到有设置的!!!(其实就是写死了,翻了他的js代码的-_-||) 设置连接到自 ...