Skip to content

Commit afd7c73

Browse files
Merge branch 'hotfix/5.3.1'
2 parents 560c599 + 798b1be commit afd7c73

File tree

8 files changed

+172
-11
lines changed

8 files changed

+172
-11
lines changed

src/Orc.Controls.Example/ViewModels/AnimatedGifViewModel.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44

55
public class AnimatedGifViewModel : ViewModelBase
66
{
7-
#region Constructors
87
public AnimatedGifViewModel()
98
{
109
}
11-
#endregion
1210
}
1311
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
namespace Orc.Controls.Example.ViewModels
2+
{
3+
using System;
4+
using System.Threading.Tasks;
5+
using Catel.MVVM;
6+
using Catel.Services;
7+
using Catel.Windows.Threading;
8+
9+
public class AnimatedTextBlockViewModel : ViewModelBase
10+
{
11+
private DispatcherTimerEx _dispatcherTimerEx;
12+
private readonly Random _random = new Random();
13+
14+
private int _currentIndex;
15+
16+
public AnimatedTextBlockViewModel(IDispatcherService dispatcherService)
17+
{
18+
_dispatcherTimerEx = new DispatcherTimerEx(dispatcherService);
19+
}
20+
21+
public string Status { get; private set; }
22+
23+
protected override Task InitializeAsync()
24+
{
25+
_dispatcherTimerEx.Tick += OnDispatcherTimerTick;
26+
_dispatcherTimerEx.Start();
27+
28+
return base.InitializeAsync();
29+
}
30+
31+
protected override Task CloseAsync()
32+
{
33+
_dispatcherTimerEx.Tick -= OnDispatcherTimerTick;
34+
_dispatcherTimerEx.Stop();
35+
36+
return base.CloseAsync();
37+
}
38+
39+
private void OnDispatcherTimerTick(object sender, EventArgs e)
40+
{
41+
_dispatcherTimerEx.Stop();
42+
_dispatcherTimerEx.Interval = TimeSpan.FromMilliseconds(_random.Next(100, 5000));
43+
_dispatcherTimerEx.Start();
44+
45+
Status = $"Status {1 + _currentIndex++}";
46+
}
47+
}
48+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<catel:UserControl x:Class="Orc.Controls.Example.Views.AnimatedTextBlock"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:catel="http://schemas.catelproject.com"
5+
xmlns:orccontrols="http://schemas.wildgums.com/orc/controls">
6+
7+
<StackPanel>
8+
<StackPanel Orientation="Horizontal">
9+
<TextBlock Text="AnimatedTextBlock"
10+
VerticalAlignment="Center"
11+
Width="150" />
12+
<orccontrols:AnimatingTextBlock HorizontalAlignment="Center"
13+
Text="{Binding Status}" />
14+
</StackPanel>
15+
</StackPanel>
16+
17+
</catel:UserControl>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Orc.Controls.Example.Views
2+
{
3+
public partial class AnimatedTextBlock
4+
{
5+
public AnimatedTextBlock()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
}

src/Orc.Controls.Example/Views/MainWindow.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
<views:AnimatedGif />
5151
</TabItem>
5252

53+
<TabItem Header="AnimatedTextBlock">
54+
<views:AnimatedTextBlock />
55+
</TabItem>
56+
5357
<TabItem Header="BindableRichTextBox">
5458
<views:BindableRichTextBox />
5559
</TabItem>

src/Orc.Controls.Tests/PublicApiFacts.Orc_Controls_HasNoBreakingChanges_Async.verified.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,20 @@ namespace Orc.Controls
5353
public string GifSource { get; set; }
5454
protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer() { }
5555
}
56+
[System.Windows.StyleTypedProperty(Property="TextBlockStyle", StyleTargetType=typeof(System.Windows.Controls.TextBlock))]
5657
public class AnimatingTextBlock : System.Windows.Controls.UserControl, Orc.Controls.Services.IStatusRepresenter
5758
{
5859
public static readonly System.Windows.DependencyProperty HideStoryboardProperty;
5960
public static readonly System.Windows.DependencyProperty ShowStoryboardProperty;
61+
public static readonly System.Windows.DependencyProperty TextAlignmentProperty;
62+
public static readonly System.Windows.DependencyProperty TextBlockStyleProperty;
6063
public static readonly System.Windows.DependencyProperty TextProperty;
6164
public AnimatingTextBlock() { }
6265
public System.Windows.Media.Animation.Storyboard? HideStoryboard { get; set; }
6366
public System.Windows.Media.Animation.Storyboard? ShowStoryboard { get; set; }
6467
public string Text { get; set; }
68+
public System.Windows.TextAlignment TextAlignment { get; set; }
69+
public System.Windows.Style? TextBlockStyle { get; set; }
6570
public override void OnApplyTemplate() { }
6671
protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer() { }
6772
public void UpdateStatus(string status) { }

src/Orc.Controls/Controls/AnimatingTextBlock/AnimatingTextBlock.cs

Lines changed: 87 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,75 @@
66
using System.Windows.Controls;
77
using System.Windows.Media.Animation;
88
using Automation;
9+
using Catel.Logging;
910
using Services;
1011

12+
[StyleTypedProperty(Property = nameof(TextBlockStyle), StyleTargetType = typeof(TextBlock))]
1113
public class AnimatingTextBlock : UserControl, IStatusRepresenter
1214
{
15+
private static readonly ILog Log = LogManager.GetCurrentClassLogger();
16+
17+
private static readonly Storyboard DefaultShowStoryboard;
18+
private static readonly Storyboard DefaultHideStoryboard;
19+
1320
private Grid? _contentGrid;
1421
private int _currentIndex = 0;
1522

23+
static AnimatingTextBlock()
24+
{
25+
var showStoryboard = new Storyboard();
26+
27+
var showAnimation = new DoubleAnimation
28+
{
29+
To = 1d,
30+
Duration = TimeSpan.FromMilliseconds(500),
31+
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseOut }
32+
};
33+
34+
Storyboard.SetTargetProperty(showAnimation, new PropertyPath(nameof(TextBlock.Opacity)));
35+
36+
showStoryboard.Children.Add(showAnimation);
37+
38+
DefaultShowStoryboard = showStoryboard;
39+
40+
var hideStoryboard = new Storyboard();
41+
42+
var hideAnimation = new DoubleAnimation
43+
{
44+
To = 0d,
45+
Duration = TimeSpan.FromMilliseconds(500),
46+
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseOut }
47+
};
48+
49+
Storyboard.SetTargetProperty(hideAnimation, new PropertyPath(nameof(TextBlock.Opacity)));
50+
51+
hideStoryboard.Children.Add(hideAnimation);
52+
53+
DefaultHideStoryboard = hideStoryboard;
54+
}
55+
1656
public AnimatingTextBlock()
1757
{
58+
SetCurrentValue(ShowStoryboardProperty, DefaultShowStoryboard);
59+
SetCurrentValue(HideStoryboardProperty, DefaultHideStoryboard);
60+
1861
Loaded += OnLoaded;
1962
}
2063

2164
#region Dependency properties
65+
66+
67+
public Style? TextBlockStyle
68+
{
69+
get { return (Style?)GetValue(TextBlockStyleProperty); }
70+
set { SetValue(TextBlockStyleProperty, value); }
71+
}
72+
73+
public static readonly DependencyProperty TextBlockStyleProperty = DependencyProperty.Register(nameof(TextBlockStyle),
74+
typeof(Style), typeof(AnimatingTextBlock), new PropertyMetadata(null));
75+
76+
77+
2278
public string Text
2379
{
2480
get { return (string)GetValue(TextProperty); }
@@ -27,15 +83,27 @@ public string Text
2783

2884
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(nameof(Text), typeof(string), typeof(AnimatingTextBlock),
2985
new PropertyMetadata(string.Empty, (sender, _) => ((AnimatingTextBlock)sender).OnTextChanged()));
30-
86+
87+
88+
public TextAlignment TextAlignment
89+
{
90+
get { return (TextAlignment)GetValue(TextAlignmentProperty); }
91+
set { SetValue(TextAlignmentProperty, value); }
92+
}
93+
94+
public static readonly DependencyProperty TextAlignmentProperty = DependencyProperty.Register(nameof(TextAlignment), typeof(TextAlignment),
95+
typeof(AnimatingTextBlock), new PropertyMetadata(TextAlignment.Left));
96+
97+
3198
public Storyboard? HideStoryboard
3299
{
33100
get { return (Storyboard?)GetValue(HideStoryboardProperty); }
34101
set { SetValue(HideStoryboardProperty, value); }
35102
}
36103

37104
public static readonly DependencyProperty HideStoryboardProperty =
38-
DependencyProperty.Register(nameof(HideStoryboard), typeof(Storyboard), typeof(AnimatingTextBlock), new PropertyMetadata(null));
105+
DependencyProperty.Register(nameof(HideStoryboard), typeof(Storyboard), typeof(AnimatingTextBlock), new PropertyMetadata());
106+
39107

40108
public Storyboard? ShowStoryboard
41109
{
@@ -44,7 +112,7 @@ public Storyboard? ShowStoryboard
44112
}
45113

46114
public static readonly DependencyProperty ShowStoryboardProperty =
47-
DependencyProperty.Register(nameof(ShowStoryboard), typeof(Storyboard), typeof(AnimatingTextBlock), new PropertyMetadata(null));
115+
DependencyProperty.Register(nameof(ShowStoryboard), typeof(Storyboard), typeof(AnimatingTextBlock), new PropertyMetadata());
48116

49117
#endregion
50118

@@ -97,7 +165,8 @@ private void OnHideStoryboardComplete(object? sender, EventArgs e)
97165

98166
private void OnHideComplete()
99167
{
100-
if (string.IsNullOrEmpty(Text))
168+
var text = Text;
169+
if (string.IsNullOrEmpty(text))
101170
{
102171
return;
103172
}
@@ -114,7 +183,7 @@ private void OnHideComplete()
114183
}
115184

116185
var textBlockToShow = (TextBlock)_contentGrid.Children[_currentIndex];
117-
textBlockToShow.SetCurrentValue(TextBlock.TextProperty, Text);
186+
textBlockToShow.SetCurrentValue(TextBlock.TextProperty, text);
118187

119188
var showStoryboard = ShowStoryboard;
120189
if (showStoryboard is not null)
@@ -162,16 +231,26 @@ private Grid CreateContent()
162231
var renderTransform = RenderTransform;
163232
SetCurrentValue(RenderTransformProperty, null);
164233

234+
var textBlockStyle = TextBlockStyle;
235+
165236
for (var i = 0; i < 2; i++)
166237
{
167238
var textBlock = new TextBlock
168239
{
169-
HorizontalAlignment = HorizontalAlignment.Left,
170-
VerticalAlignment = VerticalAlignment.Center,
240+
HorizontalAlignment = HorizontalContentAlignment,
241+
VerticalAlignment = VerticalContentAlignment,
171242
Opacity = 0d,
172-
RenderTransform = renderTransform
243+
RenderTransform = renderTransform,
244+
TextAlignment = TextAlignment,
245+
TextWrapping = TextWrapping.NoWrap,
246+
TextTrimming = TextTrimming.CharacterEllipsis,
173247
};
174248

249+
if (textBlockStyle is not null)
250+
{
251+
textBlock.Style = textBlockStyle;
252+
}
253+
175254
grid.Children.Add(textBlock);
176255
}
177256

src/Orc.Controls/Controls/BusyIndicator/VisualWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class VisualWrapper : FrameworkElement
1313
{
1414
private Visual? _child;
1515

16-
/// <summary>w
16+
/// <summary>
1717
/// Gets or sets the child.
1818
/// </summary>
1919
/// <value>The child.</value>

0 commit comments

Comments
 (0)