improved RunningBlock
This commit is contained in:
1 parent
537f0e5761
commit
1198fd1f2d
3 files changed
+46
-7
No files matched your search
@@ -8,6 +8,8 @@
|
|||||||
<StackPanel Margin="32" VerticalAlignment="Center">
|
<StackPanel Margin="32" VerticalAlignment="Center">
|
||||||
<hc:RunningBlock Content="{Binding Source={x:Static langs:Lang.Text}, Converter={StaticResource StringRepeatConverter}, ConverterParameter=5}"/>
|
<hc:RunningBlock Content="{Binding Source={x:Static langs:Lang.Text}, Converter={StaticResource StringRepeatConverter}, ConverterParameter=5}"/>
|
||||||
<hc:RunningBlock Content="{Binding Source={x:Static langs:Lang.Text}, Converter={StaticResource StringRepeatConverter}, ConverterParameter=10}" FontSize="20" FontWeight="Bold" Foreground="OrangeRed" Duration="0:0:10" Margin="0,16,0,0"/>
|
<hc:RunningBlock Content="{Binding Source={x:Static langs:Lang.Text}, Converter={StaticResource StringRepeatConverter}, ConverterParameter=10}" FontSize="20" FontWeight="Bold" Foreground="OrangeRed" Duration="0:0:10" Margin="0,16,0,0"/>
|
||||||
|
<hc:RunningBlock AutoReverse="True" Content="{Binding Source={x:Static langs:Lang.Text}, Converter={StaticResource StringRepeatConverter}, ConverterParameter=10}" FontSize="20" FontWeight="Bold" Foreground="OrangeRed" Duration="0:0:10" Margin="0,16,0,0"/>
|
||||||
|
<hc:RunningBlock Orientation="Vertical" Content="{Binding Source={x:Static langs:Lang.Text}, Converter={StaticResource StringRepeatConverter}, ConverterParameter=10}" FontSize="20" FontWeight="Bold" Foreground="OrangeRed" Duration="0:0:4" Margin="0,16,0,0"/>
|
||||||
<hc:RunningBlock Margin="0,16,0,0" Duration="0:0:20" IsRunning="{Binding IsMouseOver,RelativeSource={RelativeSource Self},Converter={StaticResource Boolean2BooleanReConverter}}">
|
<hc:RunningBlock Margin="0,16,0,0" Duration="0:0:20" IsRunning="{Binding IsMouseOver,RelativeSource={RelativeSource Self},Converter={StaticResource Boolean2BooleanReConverter}}">
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<hc:GifImage Uri="/HandyControlDemo;component/Resources/Img/QQ/1.gif" Margin="10,0"/>
|
<hc:GifImage Uri="/HandyControlDemo;component/Resources/Img/QQ/1.gif" Margin="10,0"/>
|
||||||
|
|||||||
@@ -29,6 +29,15 @@ namespace HandyControl.Controls
|
|||||||
_elementPanel = GetTemplateChild(ElementPanel) as Panel;
|
_elementPanel = GetTemplateChild(ElementPanel) as Panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register(
|
||||||
|
"Orientation", typeof(Orientation), typeof(RunningBlock), new FrameworkPropertyMetadata(default(Orientation), FrameworkPropertyMetadataOptions.AffectsRender));
|
||||||
|
|
||||||
|
public Orientation Orientation
|
||||||
|
{
|
||||||
|
get => (Orientation) GetValue(OrientationProperty);
|
||||||
|
set => SetValue(OrientationProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
public static readonly DependencyProperty DurationProperty = DependencyProperty.Register(
|
public static readonly DependencyProperty DurationProperty = DependencyProperty.Register(
|
||||||
"Duration", typeof(Duration), typeof(RunningBlock), new FrameworkPropertyMetadata(new Duration(TimeSpan.FromSeconds(5)), FrameworkPropertyMetadataOptions.AffectsRender));
|
"Duration", typeof(Duration), typeof(RunningBlock), new FrameworkPropertyMetadata(new Duration(TimeSpan.FromSeconds(5)), FrameworkPropertyMetadataOptions.AffectsRender));
|
||||||
|
|
||||||
@@ -59,6 +68,15 @@ namespace HandyControl.Controls
|
|||||||
set => SetValue(IsRunningProperty, value);
|
set => SetValue(IsRunningProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static readonly DependencyProperty AutoReverseProperty = DependencyProperty.Register(
|
||||||
|
"AutoReverse", typeof(bool), typeof(RunningBlock), new FrameworkPropertyMetadata(ValueBoxes.FalseBox, FrameworkPropertyMetadataOptions.AffectsRender));
|
||||||
|
|
||||||
|
public bool AutoReverse
|
||||||
|
{
|
||||||
|
get => (bool) GetValue(AutoReverseProperty);
|
||||||
|
set => SetValue(AutoReverseProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateContent()
|
private void UpdateContent()
|
||||||
{
|
{
|
||||||
if (_elementContent == null || _elementPanel == null) return;
|
if (_elementContent == null || _elementPanel == null) return;
|
||||||
@@ -70,14 +88,28 @@ namespace HandyControl.Controls
|
|||||||
_elementPanel.Width = _elementPanel.DesiredSize.Width;
|
_elementPanel.Width = _elementPanel.DesiredSize.Width;
|
||||||
_elementPanel.Height = _elementPanel.DesiredSize.Height;
|
_elementPanel.Height = _elementPanel.DesiredSize.Height;
|
||||||
|
|
||||||
var animation = new DoubleAnimation(-_elementPanel.Width, ActualWidth, Duration)
|
DoubleAnimation animation;
|
||||||
|
if (Orientation == Orientation.Horizontal)
|
||||||
{
|
{
|
||||||
RepeatBehavior = RepeatBehavior.Forever
|
animation = new DoubleAnimation(-_elementPanel.Width, ActualWidth, Duration)
|
||||||
};
|
{
|
||||||
Storyboard.SetTarget(animation, _elementContent);
|
RepeatBehavior = RepeatBehavior.Forever,
|
||||||
Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.X)"));
|
AutoReverse = AutoReverse
|
||||||
_storyboard.Children.Add(animation);
|
};
|
||||||
|
Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.X)"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
animation = new DoubleAnimation(-_elementPanel.Height, ActualHeight, Duration)
|
||||||
|
{
|
||||||
|
RepeatBehavior = RepeatBehavior.Forever,
|
||||||
|
AutoReverse = AutoReverse
|
||||||
|
};
|
||||||
|
Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)"));
|
||||||
|
}
|
||||||
|
|
||||||
|
Storyboard.SetTarget(animation, _elementContent);
|
||||||
|
_storyboard.Children.Add(animation);
|
||||||
_storyboard.Begin();
|
_storyboard.Begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
<ContentPresenter x:Name="PART_ContentElement" RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Left">
|
<ContentPresenter x:Name="PART_ContentElement" RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Left">
|
||||||
<ContentPresenter.RenderTransform>
|
<ContentPresenter.RenderTransform>
|
||||||
<TransformGroup>
|
<TransformGroup>
|
||||||
<TranslateTransform X="0"/>
|
<TranslateTransform/>
|
||||||
</TransformGroup>
|
</TransformGroup>
|
||||||
</ContentPresenter.RenderTransform>
|
</ContentPresenter.RenderTransform>
|
||||||
</ContentPresenter>
|
</ContentPresenter>
|
||||||
@@ -29,6 +29,11 @@
|
|||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
</Setter.Value>
|
</Setter.Value>
|
||||||
</Setter>
|
</Setter>
|
||||||
|
<Style.Triggers>
|
||||||
|
<Trigger Property="Orientation" Value="Vertical">
|
||||||
|
<Setter Property="Padding" Value="10,0"/>
|
||||||
|
</Trigger>
|
||||||
|
</Style.Triggers>
|
||||||
</Style>
|
</Style>
|
||||||
|
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
Reference in new issue
Block a user