我正在尝试在我的应用程序中添加选取框文本动画,我有两个小问题。文本来自 sqlite Db。
- 动画速度 - 如果文本 leighs 不同或文本更改,我如何为 ListView 中的所有选取框文本设置相同的速度?
2)当 UI 启动时,所有文本在起点一起显示并在结束时一起消失,但如果文本大小发生变化,那么一些文本会在中间或接近终点消失。或者有时一个文本已经消失但没有重新启动,而另一个文本没有到达终点。
.Xaml:
<ListView ItemsSource="{Binding Contacts}"
SelectedItem="{Binding SelectedContact}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
Background="#FF2F3136"
BorderThickness="0"
Grid.Row="0"
ItemContainerStyle="{StaticResource ContactCard}">
<ListView.Resources>
<Style TargetType="Label">
<EventSetter Event="MouseRightButtonUp" Handler="OnMouseRightButtonUp"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
</Trigger>
</Style.Triggers>
</Style>
</ListView.Resources>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<!--<StackPanel Orientation="Horizontal" />-->
<WrapPanel />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<!--end-->
</ListView>
名片主题
<StackPanel Orientation="Horizontal" x:Name="stack"
>
<StackPanel.Resources>
<local:NegatingConverter x:Key="NegatingConverter" />
<Storyboard x:Key="slide">
<DoubleAnimation From="90" To="{Binding Text,
ElementName=txtKron,
Converter={StaticResource NegatingConverter}}" Duration="00:00:06"
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="90">
<TextBlock Text="{Binding Message1}" FontSize="12" Foreground="White" x:Name="txtKron" Canvas.Left="0" Canvas.Top="1"/>
</Canvas>
</StackPanel>
否定转换器
public class NegatingConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is string)
{
return -(value.ToString().Length * 6);
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is double)
{
return +(double)value;
}
return value;
}
}