在 Textblock 内绑定运行会导致 WPF 中的异常 [英] Binding Run inside Textblock results in exception in WPF

查看:18
本文介绍了在 Textblock 内绑定运行会导致 WPF 中的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将两个 绑定到 TextBlock 中,如下面的代码片段所示.但我收到一个 XamlParseException.

I'm trying to bind two <Run>s inside a TextBlock as shown in the snippet below. But I'm getting an XamlParseException.

基本上我正在尝试实现这种格式:

Basically I'm trying to achieve this format:

代码编号:长描述

如果下面的代码注定失败,我还有什么其他选择?

If the below code is doomed to fail what other alternatives do I have?

<TextBlock>
    <Run FontWeight="Bold" Text="{Binding CodeNum}"/>
    <Run FontWeight="Bold" Text=": "/>
    <Run Text="{Binding LongDescription}"/>
</TextBlock>

推荐答案

我猜 LongDescriptionCodeNumis 是只读属性(不是有公共二传手).您需要将绑定更改为您在 Run

I'm guessing that either LongDescription or CodeNumis is a read-only property (doesn't have public setter). You need to change binding to be one way for all read-only properties that you use in Run

<Run Text="{Binding LongDescription, Mode=OneWay}"/>

这篇关于在 Textblock 内绑定运行会导致 WPF 中的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆