Skip to content

Commit 8259fcb

Browse files
committed
2 parents 439c632 + 09330c6 commit 8259fcb

File tree

7 files changed

+64
-40
lines changed

7 files changed

+64
-40
lines changed

MaterialDesignThemes.Wpf/Converters/MathMultipleConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public object Convert(object[] value, Type targetType, object parameter, Culture
1919

2020
double value1, value2;
2121
if (!double.TryParse(value[0].ToString(), out value1) || !double.TryParse(value[1].ToString(), out value2))
22-
return Binding.DoNothing;
22+
return 0;
2323

2424
switch (Operation)
2525
{

MaterialDesignThemes.Wpf/DialogHost.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ private static void IsOpenPropertyChangedCallback(DependencyObject dependencyObj
245245
VisualStateManager.GoToState(dialogHost, dialogHost.SelectState(), !TransitionAssist.GetDisableTransitions(dialogHost));
246246

247247
if (dialogHost.IsOpen)
248-
{
248+
{
249249
WatchWindowActivation(dialogHost);
250250
dialogHost._currentSnackbarMessageQueueUnPauseAction = dialogHost.SnackbarMessageQueue?.Pause();
251251
}
@@ -265,7 +265,6 @@ private static void IsOpenPropertyChangedCallback(DependencyObject dependencyObj
265265
// Don't attempt to Invoke if _restoreFocusDialogClose hasn't been assigned yet. Can occur
266266
// if the MainWindow has started up minimized. Even when Show() has been called, this doesn't
267267
// seem to have been set.
268-
269268
dialogHost.Dispatcher.InvokeAsync(() => dialogHost._restoreFocusDialogClose?.Focus(), DispatcherPriority.Input);
270269

271270
return;
@@ -424,7 +423,7 @@ public override void OnApplyTemplate()
424423
_contentCoverGrid.MouseLeftButtonUp += ContentCoverGridOnMouseLeftButtonUp;
425424

426425
VisualStateManager.GoToState(this, SelectState(), false);
427-
426+
428427
base.OnApplyTemplate();
429428
}
430429

MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@
297297
<Compile Include="ListBoxAssist.cs" />
298298
<Compile Include="MessageQueueExtension.cs" />
299299
<Compile Include="Palette.cs" />
300+
<Compile Include="ScaleHost.cs" />
300301
<Compile Include="Snackbar.cs" />
301302
<Compile Include="SnackbarMessage.cs" />
302303
<Compile Include="SnackbarMessageEventArgs.cs" />

MaterialDesignThemes.Wpf/ScaleHost.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Windows;
2+
3+
namespace MaterialDesignThemes.Wpf
4+
{
5+
/// <summary>
6+
/// Internal use only.
7+
/// </summary>
8+
public class ScaleHost : FrameworkElement
9+
{
10+
public static readonly DependencyProperty ScaleProperty = DependencyProperty.Register(
11+
"Scale", typeof(double), typeof(ScaleHost), new PropertyMetadata(0.0));
12+
13+
public double Scale
14+
{
15+
get { return (double) GetValue(ScaleProperty); }
16+
set { SetValue(ScaleProperty, value); }
17+
}
18+
}
19+
}

MaterialDesignThemes.Wpf/SmartHint.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Threading.Tasks;
77
using System.Windows;
88
using System.Windows.Controls;
9+
using System.Windows.Media.Animation;
910
using MaterialDesignThemes.Wpf.Converters;
1011

1112
namespace MaterialDesignThemes.Wpf
@@ -19,11 +20,13 @@ namespace MaterialDesignThemes.Wpf
1920
[TemplateVisualState(GroupName = ContentStatesGroupName, Name = ContentEmptyName)]
2021
[TemplateVisualState(GroupName = ContentStatesGroupName, Name = ContentNotEmptyName)]
2122
public class SmartHint : Control
22-
{
23+
{
2324
public const string ContentStatesGroupName = "ContentStates";
2425
public const string ContentEmptyName = "ContentEmpty";
2526
public const string ContentNotEmptyName = "ContentNotEmpty";
2627

28+
private ContentControl _floatingHintPart = null;
29+
2730
#region ManagedProperty
2831

2932
public static readonly DependencyProperty HintProxyProperty = DependencyProperty.Register(
@@ -144,13 +147,12 @@ private static void HintProxyPropertyChangedCallback(DependencyObject dependency
144147
}
145148

146149
hintProxy = dependencyPropertyChangedEventArgs.NewValue as IHintProxy;
147-
if (hintProxy != null)
148-
{
149-
hintProxy.IsVisibleChanged += smartHint.OnHintProxyIsVisibleChanged;
150-
hintProxy.ContentChanged += smartHint.OnHintProxyContentChanged;
151-
hintProxy.Loaded += smartHint.OnHintProxyContentChanged;
152-
smartHint.RefreshState(false);
153-
}
150+
if (hintProxy == null) return;
151+
152+
hintProxy.IsVisibleChanged += smartHint.OnHintProxyIsVisibleChanged;
153+
hintProxy.ContentChanged += smartHint.OnHintProxyContentChanged;
154+
hintProxy.Loaded += smartHint.OnHintProxyContentChanged;
155+
smartHint.RefreshState(false);
154156
}
155157

156158
protected virtual void OnHintProxyContentChanged(object sender, EventArgs e)
@@ -184,14 +186,16 @@ private void RefreshState(bool useTransitions)
184186

185187
if (proxy == null) return;
186188
if (!proxy.IsVisible) return;
187-
189+
188190
var action = new Action(() =>
189191
{
190-
var state = proxy.IsEmpty()
192+
var isEmpty = proxy.IsEmpty();
193+
194+
var state = isEmpty
191195
? ContentEmptyName
192196
: ContentNotEmptyName;
193197

194-
VisualStateManager.GoToState(this, state, useTransitions);
198+
VisualStateManager.GoToState(this, state, useTransitions);
195199
});
196200

197201
if (DesignerProperties.GetIsInDesignMode(this))
@@ -202,8 +206,6 @@ private void RefreshState(bool useTransitions)
202206
{
203207
Dispatcher.BeginInvoke(action);
204208
}
205-
}
206-
207-
209+
}
208210
}
209211
}

MaterialDesignThemes.Wpf/Themes/Generic.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,10 @@
522522
</VisualTransition>
523523
<VisualTransition From="Open" To="Closed">
524524
<Storyboard>
525+
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="PART_Popup" Storyboard.TargetProperty="IsOpen">
526+
<DiscreteBooleanKeyFrame Value="True" KeyTime="0:0:0" />
527+
<DiscreteBooleanKeyFrame Value="True" KeyTime="0:0:0.3" />
528+
</BooleanAnimationUsingKeyFrames>
525529
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="PART_Popup" Storyboard.TargetProperty="IsOpen">
526530
<DiscreteBooleanKeyFrame Value="True" KeyTime="0:0:0" />
527531
<DiscreteBooleanKeyFrame Value="True" KeyTime="0:0:0.3" />

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.SmartHint.xaml

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
</VisualState>
5555
</VisualStateGroup>
5656
</VisualStateManager.VisualStateGroups>
57-
5857
<ContentControl x:Name="SimpleHintTextBlock"
5958
IsTabStop="False"
6059
Visibility="{TemplateBinding UseFloating, Converter={StaticResource InverseBoolToVisConverter}}"
@@ -82,43 +81,43 @@
8281
<VisualTransition From="*" To="ContentNotEmpty">
8382
<Storyboard>
8483
<DoubleAnimation Storyboard.TargetName="FloatingHintTextBlock" Storyboard.TargetProperty="Opacity"
85-
Duration="0:0:0.3" To="{TemplateBinding HintOpacity}"
86-
EasingFunction="{StaticResource AnimationEasingFunction}"/>
87-
<DoubleAnimation Storyboard.TargetName="FloatingHintTextBlock" Storyboard.TargetProperty="Tag"
88-
Duration="0:0:0.3" To="1"
89-
EasingFunction="{StaticResource AnimationEasingFunction}"/>
84+
Duration="0:0:0.3" To="{TemplateBinding HintOpacity}"
85+
EasingFunction="{StaticResource AnimationEasingFunction}"/>
86+
<DoubleAnimation Storyboard.TargetName="ScaleHost" Storyboard.TargetProperty="Scale"
87+
Duration="0:0:0.3" To="1"
88+
EasingFunction="{StaticResource AnimationEasingFunction}"/>
9089
</Storyboard>
9190
</VisualTransition>
9291
<VisualTransition From="*" To="ContentEmpty">
9392
<Storyboard>
9493
<DoubleAnimation Storyboard.TargetName="FloatingHintTextBlock" Storyboard.TargetProperty="Opacity"
95-
Duration="0:0:0.3"
96-
EasingFunction="{StaticResource AnimationEasingFunction}"/>
97-
<DoubleAnimation Storyboard.TargetName="FloatingHintTextBlock" Storyboard.TargetProperty="Tag"
98-
Duration="0:0:0.3"
99-
EasingFunction="{StaticResource AnimationEasingFunction}"/>
94+
Duration="0:0:0.3"
95+
EasingFunction="{StaticResource AnimationEasingFunction}"/>
96+
<DoubleAnimation Storyboard.TargetName="ScaleHost" Storyboard.TargetProperty="Scale"
97+
Duration="0:0:0.3"
98+
EasingFunction="{StaticResource AnimationEasingFunction}"/>
10099
</Storyboard>
101100
</VisualTransition>
102101
</VisualStateGroup.Transitions>
103102
<VisualState x:Name="ContentNotEmpty">
104103
<Storyboard>
105104
<DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FloatingHintTextBlock"
106-
Duration="0" To="{TemplateBinding HintOpacity}" />
107-
<DoubleAnimation Storyboard.TargetName="FloatingHintTextBlock" Storyboard.TargetProperty="Tag"
108-
Duration="0" To="1"/>
105+
Duration="0" To="{TemplateBinding HintOpacity}" />
106+
<DoubleAnimation Storyboard.TargetName="ScaleHost" Storyboard.TargetProperty="Scale"
107+
Duration="0" To="1"/>
109108
</Storyboard>
110109
</VisualState>
111110
<VisualState x:Name="ContentEmpty">
112111
<Storyboard>
113112
<DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FloatingHintTextBlock"
114-
Duration="0" />
115-
<DoubleAnimation Storyboard.TargetName="FloatingHintTextBlock" Storyboard.TargetProperty="Tag"
116-
Duration="0" />
113+
Duration="0" />
114+
<DoubleAnimation Storyboard.TargetName="ScaleHost" Storyboard.TargetProperty="Scale"
115+
Duration="0" />
117116
</Storyboard>
118117
</VisualState>
119118
</VisualStateGroup>
120119
</VisualStateManager.VisualStateGroups>
121-
120+
<wpf:ScaleHost x:Name="ScaleHost" />
122121
<ContentControl x:Name="FloatingHintTextBlock"
123122
Visibility="{TemplateBinding UseFloating, Converter={StaticResource BoolToVisConverter}}"
124123
Content="{TemplateBinding Hint}"
@@ -137,14 +136,14 @@
137136
<ScaleTransform>
138137
<ScaleTransform.ScaleX>
139138
<MultiBinding Converter="{StaticResource RangePositionConverter}">
140-
<Binding Path="Tag" ElementName="FloatingHintTextBlock"/>
139+
<Binding Path="Scale" ElementName="ScaleHost"/>
141140
<Binding Path="FloatingScale" RelativeSource="{RelativeSource TemplatedParent}"/>
142141
<Binding Source="{StaticResource NoContentFloatingScale}"/>
143142
</MultiBinding>
144143
</ScaleTransform.ScaleX>
145144
<ScaleTransform.ScaleY>
146145
<MultiBinding Converter="{StaticResource RangePositionConverter}">
147-
<Binding Path="Tag" ElementName="FloatingHintTextBlock"/>
146+
<Binding Path="Scale" ElementName="ScaleHost"/>
148147
<Binding Path="FloatingScale" RelativeSource="{RelativeSource TemplatedParent}"/>
149148
<Binding Source="{StaticResource NoContentFloatingScale}"/>
150149
</MultiBinding>
@@ -157,13 +156,13 @@
157156
<TranslateTransform>
158157
<TranslateTransform.X>
159158
<MultiBinding Converter="{StaticResource TranslateConverter}">
160-
<Binding Path="Tag" ElementName="FloatingHintTextBlock"/>
159+
<Binding Path="Scale" ElementName="ScaleHost"/>
161160
<Binding Path="FloatingOffset.X" RelativeSource="{RelativeSource TemplatedParent}"/>
162161
</MultiBinding>
163162
</TranslateTransform.X>
164163
<TranslateTransform.Y>
165164
<MultiBinding Converter="{StaticResource TranslateConverter}">
166-
<Binding Path="Tag" ElementName="FloatingHintTextBlock"/>
165+
<Binding Path="Scale" ElementName="ScaleHost"/>
167166
<Binding Path="FloatingOffset.Y" RelativeSource="{RelativeSource TemplatedParent}"/>
168167
</MultiBinding>
169168
</TranslateTransform.Y>

0 commit comments

Comments
 (0)