Non breaking space in XAML vs. code
        Posted  
        
            by Henrik Söderlund
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Henrik Söderlund
        
        
        
        Published on 2010-05-31T13:18:27Z
        Indexed on 
            2010/05/31
            13:23 UTC
        
        
        Read the original article
        Hit count: 1879
        
This works fine, and correctly inserts non-breaking spaces into the string:
<TextBlock Text="Non Breaking Text Here"></TextBlock>
But what I really need is to replace spaces with non-breaking spaces during data binding. So I wrote a simple value converter that replaces spaces with " ". It does indeed replace spaces with " " but " " is displayed literally instead of showing as a non-breaking space. This is my converter:  
public class SpaceToNbspConverter : IValueConverter
{
    #region IValueConverter Members
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return value.ToString().Replace(" ", " ");
    }
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
    #endregion
}
Does anybody know why it works in XAML, but not in code?
/Henrik
© Stack Overflow or respective owner