Binding Run inside Textblock results in exception in WPF

时间秒杀一切 提交于 2020-08-27 03:39:36

问题


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:

CodeNum: LongDescription

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>

回答1:


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}"/>


来源:https://stackoverflow.com/questions/30551372/binding-run-inside-textblock-results-in-exception-in-wpf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!