我正在嘗試在我的代碼中添加選取框文本影片。我在WPF Marquee Text Animation 中找到了作業代碼 但是當我嘗試將它添加到我的 ItemContainerStyle 我得到錯誤:命名空間前綴“Local”沒有定義。也許有人可以幫助我。我不確定如何在我的專案容器樣式中定義NegatingConverter。謝謝。
錯誤代碼行:
<local:NegatingConverter x:Key="NegatingConverter" />
代碼:
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;
}
}
}
Xml:
<ListView ItemsSource="{Binding Messages}"
Background="Transparent"
BorderBrush="Transparent"
ItemContainerStyle="{StaticResource ChatItem}"
Margin="8,0,0,0"
Grid.Row="1"
>
</ListView>
專案容器樣式:
<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>
uj5u.com熱心網友回復:
您沒有在 xaml 中宣告轉換器的命名空間
改變
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
到
<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">
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/393096.html
