1

I'm working on a WPF application and I need to italicize some text in front of a string variable that is displayed on the same line. I want to use:

<TextBlock Foreground="LightGray" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="18" Margin="20,0,0,0" TextWrapping="Wrap">
    <Run Text="Conflicts: " FontStyle="Italic"/>
    <Run Text="{Binding ElementName=DropDown, Path=SelectedItem.Conflicts}" />
</TextBlock>

But when I do this the app freezes. No error, and it isn't just taking a long time, unless for some reason it's taking 5+ minutes to load like 1 line of code, which I do not suspect.

However I know it can load the string variable because it works perfectly fine when I use:

<TextBlock Foreground="LightGray" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="18" Text="{Binding ElementName=DropDown, Path=SelectedItem.Conflicts}" Margin="20,0,0,0" TextWrapping="Wrap"/>

I am fairly new to XAML, so it's possible I'm missing something obvious but I have no idea why one works and the other does not. Using Run Text never seems to work for me if bound to a string variable, but I can have it work with explicit text like:

<TextBlock Foreground="LightGray" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="18" Margin="20,0,0,0" TextWrapping="Wrap">
    <Run Text="Conflicts: " FontStyle="Italic"/>
</TextBlock>

I need to have them appear on the same line, so if anyone knows how to get Text Run to work with a string variable or to somehow ignore the newline created from using two textblocks that would be a big help.

I have also tried using a converter with Run Text but anything that uses a string variable with Run Text seems to freeze the application.

3
  • Can you show your SelectedItem.Conflicts? Is it by any chance readonly or not a property? Commented Oct 6, 2023 at 22:55
  • asking because both docs (learn.microsoft.com/en-us/dotnet/api/…) and this answer (stackoverflow.com/a/30551404/12533852) seem to mention setting one way binding Commented Oct 6, 2023 at 23:01
  • @Kortney: Does <Run Text="{Binding ElementName=DropDown, Path=SelectedItem.Conflicts, Mode=OneTime}" /> work better? What does the Conflicts property return? Commented Oct 9, 2023 at 15:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.