Skip to content

Commit 6478a18

Browse files
committed
fix transition issues #73 for combos and text boxes.
1 parent 986e6a3 commit 6478a18

File tree

3 files changed

+160
-113
lines changed

3 files changed

+160
-113
lines changed

MaterialDesignThemes.Wpf/TextFieldAssist.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,23 @@ private static void TextBoxViewMarginPropertyChangedCallback(
184184

185185
private static void TextPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
186186
{
187+
var frameworkElement = (FrameworkElement)dependencyObject;
188+
189+
if (frameworkElement == null) return;
190+
191+
var state = string.IsNullOrEmpty((dependencyPropertyChangedEventArgs.NewValue ?? "").ToString())
192+
? "MaterialDesignStateTextEmpty"
193+
: "MaterialDesignStateTextNotEmpty";
194+
195+
if (frameworkElement.IsLoaded)
196+
{
197+
VisualStateManager.GoToState(frameworkElement, state, true);
198+
}
199+
else
200+
{
201+
frameworkElement.Loaded += (sender, args) => VisualStateManager.GoToState(frameworkElement, state, false);
202+
}
203+
187204
SetIsNullOrEmpty(dependencyObject, string.IsNullOrEmpty((dependencyPropertyChangedEventArgs.NewValue ?? "").ToString()));
188205
}
189206

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ComboBox.xaml

Lines changed: 71 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -486,61 +486,80 @@
486486
</ControlTemplate>
487487

488488
<ControlTemplate x:Key="MaterialDesignFloatingHintComboBoxTemplate" TargetType="{x:Type ComboBox}">
489-
<ControlTemplate.Resources>
490-
<Storyboard x:Key="MoveHintAsideStoryboard">
491-
<DoubleAnimation Duration="0:0:0.3"
492-
Storyboard.TargetName="Hint"
493-
Storyboard.TargetProperty="FontSize"
494-
To="10">
495-
<DoubleAnimation.EasingFunction>
496-
<SineEase EasingMode="EaseOut" />
497-
</DoubleAnimation.EasingFunction>
498-
</DoubleAnimation>
499-
<DoubleAnimation Duration="0:0:0.3"
500-
Storyboard.TargetName="Hint"
501-
Storyboard.TargetProperty="Opacity"
502-
To="1">
503-
<DoubleAnimation.EasingFunction>
504-
<SineEase EasingMode="EaseOut" />
505-
</DoubleAnimation.EasingFunction>
506-
</DoubleAnimation>
507-
<ThicknessAnimation Duration="0:0:0.3"
508-
Storyboard.TargetName="Hint"
509-
Storyboard.TargetProperty="(FrameworkElement.Margin)"
510-
To="0,-12,0,0">
511-
<ThicknessAnimation.EasingFunction>
512-
<SineEase EasingMode="EaseOut" />
513-
</ThicknessAnimation.EasingFunction>
514-
</ThicknessAnimation>
515-
</Storyboard>
516-
<Storyboard x:Key="MoveHintBackStoryboard">
517-
<DoubleAnimation Duration="0:0:0.3"
518-
Storyboard.TargetName="Hint"
519-
Storyboard.TargetProperty="FontSize">
520-
<DoubleAnimation.EasingFunction>
521-
<SineEase EasingMode="EaseOut" />
522-
</DoubleAnimation.EasingFunction>
523-
</DoubleAnimation>
524-
<DoubleAnimation Duration="0:0:0.3"
525-
Storyboard.TargetName="Hint"
526-
Storyboard.TargetProperty="Opacity">
527-
<DoubleAnimation.EasingFunction>
528-
<SineEase EasingMode="EaseOut" />
529-
</DoubleAnimation.EasingFunction>
530-
</DoubleAnimation>
531-
<ThicknessAnimation Duration="0:0:0.3"
532-
Storyboard.TargetName="Hint"
533-
Storyboard.TargetProperty="(FrameworkElement.Margin)">
534-
<ThicknessAnimation.EasingFunction>
535-
<SineEase EasingMode="EaseOut" />
536-
</ThicknessAnimation.EasingFunction>
537-
</ThicknessAnimation>
538-
</Storyboard>
539-
</ControlTemplate.Resources>
540489
<Grid x:Name="templateRoot">
490+
<VisualStateManager.VisualStateGroups>
491+
<VisualStateGroup x:Name="MaterialDesignStates">
492+
<VisualStateGroup.Transitions>
493+
<VisualTransition From="*" To="MaterialDesignStateTextNotEmpty">
494+
<Storyboard>
495+
<DoubleAnimation Storyboard.TargetProperty="FontSize" Storyboard.TargetName="Hint"
496+
Duration="0:0:0.3" To="10">
497+
<DoubleAnimation.EasingFunction>
498+
<SineEase EasingMode="EaseOut" />
499+
</DoubleAnimation.EasingFunction>
500+
</DoubleAnimation>
501+
<DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Hint"
502+
Duration="0:0:0.3" To="1">
503+
<DoubleAnimation.EasingFunction>
504+
<SineEase EasingMode="EaseOut" />
505+
</DoubleAnimation.EasingFunction>
506+
</DoubleAnimation>
507+
<ThicknessAnimation Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="Hint"
508+
Duration="0:0:0.3" To="1,-12,1,0">
509+
<ThicknessAnimation.EasingFunction>
510+
<SineEase EasingMode="EaseOut" />
511+
</ThicknessAnimation.EasingFunction>
512+
</ThicknessAnimation>
513+
</Storyboard>
514+
</VisualTransition>
515+
<VisualTransition From="*" To="MaterialDesignStateTextEmpty">
516+
<Storyboard>
517+
<DoubleAnimation Storyboard.TargetProperty="FontSize" Storyboard.TargetName="Hint"
518+
Duration="0:0:0.3">
519+
<DoubleAnimation.EasingFunction>
520+
<SineEase EasingMode="EaseOut" />
521+
</DoubleAnimation.EasingFunction>
522+
</DoubleAnimation>
523+
<DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Hint"
524+
Duration="0:0:0.3">
525+
<DoubleAnimation.EasingFunction>
526+
<SineEase EasingMode="EaseOut" />
527+
</DoubleAnimation.EasingFunction>
528+
</DoubleAnimation>
529+
<ThicknessAnimation Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="Hint"
530+
Duration="0:0:0.3">
531+
<ThicknessAnimation.EasingFunction>
532+
<SineEase EasingMode="EaseOut" />
533+
</ThicknessAnimation.EasingFunction>
534+
</ThicknessAnimation>
535+
</Storyboard>
536+
</VisualTransition>
537+
</VisualStateGroup.Transitions>
538+
<VisualState x:Name="MaterialDesignStateTextNotEmpty">
539+
<Storyboard>
540+
<DoubleAnimation Storyboard.TargetProperty="FontSize" Storyboard.TargetName="Hint"
541+
Duration="0" To="10" />
542+
<DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Hint"
543+
Duration="0" To="1" />
544+
<ThicknessAnimation Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="Hint"
545+
Duration="0" To="1,-12,1,0" />
546+
</Storyboard>
547+
</VisualState>
548+
<VisualState x:Name="MaterialDesignStateTextEmpty">
549+
<Storyboard>
550+
<DoubleAnimation Storyboard.TargetProperty="FontSize" Storyboard.TargetName="Hint"
551+
Duration="0" />
552+
<DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Hint"
553+
Duration="0" />
554+
<ThicknessAnimation Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="Hint"
555+
Duration="0" />
556+
</Storyboard>
557+
</VisualState>
558+
</VisualStateGroup>
559+
</VisualStateManager.VisualStateGroups>
541560
<Grid Margin="0 12 0 0"
542561
SnapsToDevicePixels="True"
543-
UseLayoutRounding="True">
562+
UseLayoutRounding="True">
544563
<Grid.ColumnDefinitions>
545564
<ColumnDefinition Width="*" />
546565
<ColumnDefinition Width="0" MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" />
@@ -610,14 +629,6 @@
610629
</Grid>
611630
</Grid>
612631
<ControlTemplate.Triggers>
613-
<Trigger Property="wpf:TextFieldAssist.IsNullOrEmpty" Value="False">
614-
<Trigger.EnterActions>
615-
<BeginStoryboard x:Name="MoveHintAsideStoryboard_BeginStoryboard" Storyboard="{StaticResource MoveHintAsideStoryboard}" />
616-
</Trigger.EnterActions>
617-
<Trigger.ExitActions>
618-
<BeginStoryboard x:Name="MoveHintBackStoryboard_BeginStoryboard" Storyboard="{StaticResource MoveHintBackStoryboard}" />
619-
</Trigger.ExitActions>
620-
</Trigger>
621632

622633
<Trigger Property="IsEditable" Value="True">
623634
<Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible" />

0 commit comments

Comments
 (0)