c# - 如何在 Xamarin.Forms 中用引号将字符串括起来

标签 c# xamarin xamarin.forms

所以我有一个标签绑定(bind)到我的 View 模型中的某些文本,如下所示:

<Label VerticalOptions="Center" Text="{Binding Note, StringFormat='&quot;{0}&quot;'}" Style="{StaticResource ListItemSubTitleStyleDefault}" LineBreakMode="WordWrap" FontAttributes="Italic"/>

我试图让注释像这样用引号括起来

"I am a Note"

查看一些 WPF 答案,它建议在 StringFormat 属性中使用以下内容'“{0}”'

但这似乎不起作用。有谁知道如何在 Xamarin.Forms 中将 Labels 文本括在引号中?

最佳答案

正如您所见,对于这种情况,Xamarin.Forms 与 WPF 不同。对于 Xamarin,请执行以下操作:

<Label VerticalOptions="Center" Text="{Binding Note, StringFormat='{}&quot;{0}&quot;'}" .../>

为了防止运行时忽略双引号,第一个双引号要么必须转义(如上所述),要么不能立即跟在单引号后面(见下文)。

例如,在两者之间添加空格也可以:

<Label VerticalOptions="Center" Text="{Binding Note, StringFormat=' &quot;{0}&quot;'}" .../>

使用后一种解决方案,双引号之前至少会呈现一个字符。

关于c# - 如何在 Xamarin.Forms 中用引号将字符串括起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46853137/

相关文章:

c# - 如何在解决方案中获取给定类的完整命名空间的程序集名称和类名称?

ios - 使用 Xamarin.iOS 检测嵌入 View 内的按钮按下

xaml - Xamarin 自定义 View 按钮绑定(bind)

c# - Xamarin Forms ListView 性能

c# - 使用 .NET 3.5 处理大型 XML 文件

c# - LINQ让重复数据

c# - Razor 中的下拉绑定(bind) onchange 方法

xaml - Xaml 中的列表<颜色>

c# - 在 C# 中从后端发送 UWP 原始通知

c# - SQLite 在 CreateTablesAsync 上挂起 - Xamarin Forms