Vahid
Vahid

Reputation: 5444

Binding Run inside Textblock results in exception in WPF

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>

Upvotes: 16

Views: 13133

Answers (1)

dkozl
dkozl

Reputation: 33364

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

Upvotes: 36

Related Questions