Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

WPF Marquee Text Animation in ListView

I’m trying to add marquee text animation in my code. I found working code in
WPF Marquee Text Animation
But when i trying to add it to my ItemContainerStyle i got error: The namespace prefix "Local" is not defined. Maybe someone can help me.
i’m not sure how to define NegatingConverter in my Item Container Style. Thx.

Error code line:

 <local:NegatingConverter x:Key="NegatingConverter" />

Code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

namespace Line1_9_WPF
{
    public class NegatingConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is double)
            {
                return -((double)value);
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is double)
            {
                return +(double)value;
            }
            return value;
        }
    }
}

Xaml:

             <ListView ItemsSource="{Binding Messages}"
                              Background="Transparent"
                      
                              BorderBrush="Transparent"
                              ItemContainerStyle="{StaticResource ChatItem}"
                              Margin="8,0,0,0"
                    Grid.Row="1"
                >
                </ListView>

ItemContainerStyle:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style TargetType="ListViewItem" x:Key="ChatItem">
        <Setter Property="Background"  Value="#393B40"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>

                        <StackPanel Orientation="Vertical">
                            <Label Content="{Binding Line}"
                               Foreground="White"
                              />
                        <Label Content="{Binding MessageF1}"
                               Foreground="Gray"
                              />
                        <Label Content="{Binding MessageF2}"
                               Foreground="Gray"
                              />

                        <Label Content="{Binding Time}"
                               Foreground="Gray"
                              />
                        <StackPanel Orientation="Horizontal" x:Name="stack">
                            <StackPanel.Resources>
                                <local:NegatingConverter x:Key="NegatingConverter" />
                                <Storyboard x:Key="slide">
                                    <DoubleAnimation From="0" To="{Binding Width, ElementName=canvas, Converter={StaticResource NegatingConverter}}" Duration="00:00:03"
                      Storyboard.TargetProperty="X"
                      Storyboard.TargetName="transferCurreny"
                      RepeatBehavior="Forever"/>
                                </Storyboard>
                            </StackPanel.Resources>
                            <StackPanel.RenderTransform>
                                <TranslateTransform x:Name="transferCurreny" X="0"/>
                            </StackPanel.RenderTransform>
                            <StackPanel.Triggers>
                                <EventTrigger RoutedEvent="StackPanel.Loaded">
                                    <BeginStoryboard Storyboard="{StaticResource slide}" />
                                </EventTrigger>
                                <EventTrigger RoutedEvent="StackPanel.SizeChanged">
                                    <BeginStoryboard Storyboard="{StaticResource slide}" />
                                </EventTrigger>
                            </StackPanel.Triggers>
                            <Canvas x:Name="canvas" Width="{Binding ActualWidth, ElementName=stack}">
                                <TextBlock Text="StackOverflow" FontSize="25"  x:Name="txtKron" Canvas.Left="0"/>
                                <TextBlock Text="{Binding Text, ElementName=txtKron}" FontSize="25" Canvas.Left="{Binding Width, ElementName=canvas}"/>
                            </Canvas>
                        </StackPanel>
                    </StackPanel>

                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
</ResourceDictionary>

>Solution :

You are not declaring the namespace for the converter in the xaml

Change

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

To

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:local="clr-namespace:Line1_9_WPF">
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading