0

I tried to show the RSS text in one line but it doesn't work. Any "title" from the RSS gets a new line. there is any way to solve it?

<UserControl x:Class="Example.UserControls.Footer"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:local="clr-namespace:EcoBuy.UserControls"
         mc:Ignorable="d" 
         d:DesignHeight="54" d:DesignWidth="1920">
<UserControl.Resources>
    <XmlDataProvider x:Key="DataRss"
                     XPath="//item"
                     Source="https://rss.walla.co.il/feed/127"></XmlDataProvider>
</UserControl.Resources>
<Grid FlowDirection="RightToLeft">
    <ListBox ItemsSource="{Binding Source={StaticResource DataRss}}"
             Margin="0,0,0,-110">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal" >
                    <TextBlock x:Name="rssText" Text="{Binding XPath=title}" TextWrapping="NoWrap"> 
                    </TextBlock>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Grid>
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • So, you don't want to use ListBox but only one TextBox which will contain all titles? Why TextBox? Maybe similar question: https://stackoverflow.com/questions/345385/wpf-textblock-binding-with-liststring – user2250152 Feb 18 '21 at 06:18

2 Answers2

0

You can try to use MaxLines="1"

0

Maybe try to use an IValueConverter to remove possible newlines in your feed? Something like this:

public class RemoveNewlinesConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (value is string text)
        {
            return text.Replace("\n", "").Replace("\r", "");
        }
        return null;
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}
F. Robb
  • 46
  • 5