我试图在 UWP 中为滚动查看器的水平偏移设置动画,但动画目标未识别附加属性。
<Grid x:Name="maingrid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.Resources>
<Storyboard x:Key="animation" x:Name="animation">
<DoubleAnimation Storyboard.TargetName="scrolviewer"
Storyboard.TargetProperty="(local:ScrollviewerBehaviour.Horizontalofset)"
Duration="0:0:1" From="0" To="80"/>
</Storyboard>
</Grid.Resources>
<Button Width="100" Height="50" Click="Button_Click_1"/>
<ScrollViewer x:Name="scrolviewer" local:ScrollviewerBehaviour.Horizontalofset="0" Width="200" Height="100" HorizontalScrollBarVisibility="Visible">
<TextBlock Text="aaaaaaaaaaaaaaaaaaaaaaaaa" FontSize="20"/>
</ScrollViewer>
</Grid>
这是c#代码
public class ScrollviewerBehaviour
{
public static readonly DependencyProperty Horizontalofsetproperty =
DependencyProperty.RegisterAttached("Horizontalofset",
typeof(double),
typeof(ScrollviewerBehaviour),
new PropertyMetadata(0,new PropertyChangedCallback(OnHorizontalofsetchanged)));
public static void SetHorizontalofset(ScrollViewer element, double value)
{
element.SetValue(Horizontalofsetproperty, value);
}
public static double GetHorizontalofset(ScrollViewer element)
{
return (double)element.GetValue(Horizontalofsetproperty);
}
public static void OnHorizontalofsetchanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
var scrollviewer = (sender as ScrollViewer);
scrollviewer.ChangeView((double)e.NewValue, scrollviewer.VerticalOffset, scrollviewer.ZoomFactor);
}
}
我想念什么吗