Skip to content

Commit f5b9afc

Browse files
committed
complete floating progress styling, and demo
1 parent be2016e commit f5b9afc

File tree

6 files changed

+196
-31
lines changed

6 files changed

+196
-31
lines changed

MainDemo.Wpf/App.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Application x:Class="MaterialDesignColors.WpfExample.App"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
StartupUri="ProvingGround.xaml">
4+
StartupUri="MainWindow.xaml">
55
<Application.Resources>
66
<ResourceDictionary>
77
<ResourceDictionary.MergedDictionaries>

MainDemo.Wpf/Buttons.xaml

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -221,23 +221,54 @@
221221

222222
<TextBlock Style="{StaticResource MaterialDesignHeadlineTextBlock}"
223223
Grid.Row="5" Margin="0 12 0 12">Buttons - With Progress</TextBlock>
224-
<StackPanel Grid.Row="6" >
225-
<Button Command="{Binding DismissComand}"
226-
Style="{StaticResource MaterialDesignRaisedButton}"
227-
HorizontalAlignment="Left"
228-
materialDesign:ButtonProgressAssist.Value="{Binding DismissButtonProgress}"
229-
Visibility="{Binding ShowDismissButton, Converter={StaticResource BooleanToVisibilityConverter}}">
230-
<StackPanel Orientation="Horizontal">
231-
<TextBlock>DISMISS</TextBlock>
232-
<materialDesign:PackIcon Margin="4 .5 0 0" Kind="Close" />
233-
</StackPanel>
234-
</Button>
235-
<Grid Height="32"
236-
Visibility="{Binding ShowDismissButton, Converter={StaticResource InvertedBooleanToVisibilityConverter}}">
224+
<StackPanel Grid.Row="6" Orientation="Horizontal">
225+
<Grid Width="124">
226+
<!-- raised button with progress, useful to auto dismiss/accept something -->
227+
<Button Command="{Binding DismissComand}"
228+
Style="{StaticResource MaterialDesignRaisedButton}"
229+
HorizontalAlignment="Left"
230+
materialDesign:ButtonProgressAssist.Value="{Binding DismissButtonProgress}"
231+
Visibility="{Binding ShowDismissButton, Converter={StaticResource BooleanToVisibilityConverter}}">
232+
<StackPanel Orientation="Horizontal">
233+
<TextBlock>DISMISS</TextBlock>
234+
<materialDesign:PackIcon Margin="4 .5 0 0" Kind="Close" />
235+
</StackPanel>
236+
</Button>
237237
<TextBlock Text="{Binding DemoRestartCountdownText}"
238238
VerticalAlignment="Center"
239+
Visibility="{Binding ShowDismissButton, Converter={StaticResource InvertedBooleanToVisibilityConverter}}"
239240
/>
240-
</Grid>
241+
</Grid>
242+
243+
<!-- floating action button with progress -->
244+
<Button Style="{StaticResource MaterialDesignFloatingActionLightButton}" Margin="24 0 12 0"
245+
Command="{Binding SaveComand}"
246+
materialDesign:ButtonProgressAssist.IsIndicatorVisible="{Binding IsSaving}"
247+
materialDesign:ButtonProgressAssist.Value="{Binding SaveProgress}">
248+
249+
<!-- simple example of toggling/animating pack icon with a data trigger-->
250+
<materialDesign:PackIcon Height="24" Width="24">
251+
<materialDesign:PackIcon.Style>
252+
<Style TargetType="materialDesign:PackIcon" BasedOn="{StaticResource {x:Type materialDesign:PackIcon}}">
253+
<Setter Property="Kind" Value="CloudSync" />
254+
<Style.Triggers>
255+
<DataTrigger Binding="{Binding IsSaveComplete}" Value="True">
256+
<Setter Property="Kind" Value="Check" />
257+
<DataTrigger.EnterActions>
258+
<BeginStoryboard>
259+
<Storyboard>
260+
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:0.8" />
261+
</Storyboard>
262+
</BeginStoryboard>
263+
</DataTrigger.EnterActions>
264+
</DataTrigger>
265+
</Style.Triggers>
266+
</Style>
267+
</materialDesign:PackIcon.Style>
268+
</materialDesign:PackIcon>
269+
270+
</Button>
271+
241272
</StackPanel>
242273
<Border Margin="0 16 0 0" BorderThickness="0 1 0 0" BorderBrush="{DynamicResource MaterialDesignDivider}" Grid.Row="7" />
243274

MainDemo.Wpf/ButtonsViewModel.cs

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ public ButtonsViewModel()
2121
DismissComand = new AnotherCommandImplementation(_ => dismissRequested = true);
2222
ShowDismissButton = true;
2323

24-
//just some demo code...it's up to you to set up the
25-
//progress on the button as it would be with a progress bar.
24+
#region DISMISS button demo control
25+
//just some demo code for the DISMISS button...it's up to you to set
26+
//up the progress on the button as it would be with a progress bar.
2627
//and then hide the button, do whatever action you want to do
2728
new DispatcherTimer(
2829
TimeSpan.FromMilliseconds(100),
@@ -62,8 +63,47 @@ public ButtonsViewModel()
6263
}
6364

6465
}), Dispatcher.CurrentDispatcher);
66+
#endregion
67+
68+
//just some demo code for the SAVE button
69+
SaveComand = new AnotherCommandImplementation(_ =>
70+
{
71+
if (IsSaveComplete == true)
72+
{
73+
IsSaveComplete = false;
74+
return;
75+
}
76+
77+
if (SaveProgress != 0) return;
78+
79+
var started = DateTime.Now;
80+
IsSaving = true;
81+
82+
new DispatcherTimer(
83+
TimeSpan.FromMilliseconds(50),
84+
DispatcherPriority.Normal,
85+
new EventHandler((o, e) =>
86+
{
87+
var totalDuration = started.AddSeconds(3).Ticks - started.Ticks;
88+
var currentProgress = DateTime.Now.Ticks - started.Ticks;
89+
var currentProgressPercent = 100.0 / totalDuration * currentProgress;
90+
91+
SaveProgress = currentProgressPercent;
92+
93+
if (SaveProgress >= 100)
94+
{
95+
IsSaveComplete = true;
96+
IsSaving = false;
97+
SaveProgress = 0;
98+
((DispatcherTimer)o).Stop();
99+
}
100+
101+
}), Dispatcher.CurrentDispatcher);
102+
});
65103
}
66104

105+
#region Dismiss button demo
106+
67107
public ICommand DismissComand { get; }
68108

69109
public bool ShowDismissButton
@@ -92,6 +132,35 @@ private void UpdateDemoRestartCountdownText(DateTime endTime, out bool isComplet
92132
isComplete = seconds == 0;
93133
}
94134

135+
#endregion
136+
137+
#region floating Save button demo
138+
139+
public ICommand SaveComand { get; }
140+
141+
private bool _isSaving;
142+
public bool IsSaving
143+
{
144+
get { return _isSaving; }
145+
private set { this.MutateVerbose(ref _isSaving, value, RaisePropertyChanged()); }
146+
}
147+
148+
private bool _isSaveComplete;
149+
public bool IsSaveComplete
150+
{
151+
get { return _isSaveComplete; }
152+
private set { this.MutateVerbose(ref _isSaveComplete, value, RaisePropertyChanged()); }
153+
}
154+
155+
private double _saveProgress;
156+
public double SaveProgress
157+
{
158+
get { return _saveProgress; }
159+
private set { this.MutateVerbose(ref _saveProgress, value, RaisePropertyChanged()); }
160+
}
161+
162+
#endregion
163+
95164
public event PropertyChangedEventHandler PropertyChanged;
96165

97166
private Action<PropertyChangedEventArgs> RaisePropertyChanged()

MaterialDesignThemes.Wpf/ButtonProgressAssist.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ public static double GetValue(DependencyObject element)
5050
return (double)element.GetValue(ValueProperty);
5151
}
5252

53+
public static readonly DependencyProperty IsIndeterminateProperty = DependencyProperty.RegisterAttached(
54+
"IsIndeterminate", typeof(bool), typeof(ButtonProgressAssist), new FrameworkPropertyMetadata(default(bool)));
55+
56+
public static void SetIsIndeterminate(DependencyObject element, bool isIndeterminate)
57+
{
58+
element.SetValue(IsIndeterminateProperty, isIndeterminate);
59+
}
60+
61+
public static bool GetIsIndeterminate(DependencyObject element)
62+
{
63+
return (bool)element.GetValue(IndicatorForegroundProperty);
64+
}
65+
5366
public static readonly DependencyProperty IndicatorForegroundProperty = DependencyProperty.RegisterAttached(
5467
"IndicatorForeground", typeof(Brush), typeof(ButtonProgressAssist), new FrameworkPropertyMetadata(default(Brush)));
5568

@@ -74,6 +87,19 @@ public static void SetIndicatorBackground(DependencyObject element, Brush indica
7487
public static Brush GetIndicatorBackground(DependencyObject element)
7588
{
7689
return (Brush)element.GetValue(IndicatorForegroundProperty);
77-
}
90+
}
91+
92+
public static readonly DependencyProperty IsIndicatorVisibleProperty = DependencyProperty.RegisterAttached(
93+
"IsIndicatorVisible", typeof(bool), typeof(ButtonProgressAssist), new FrameworkPropertyMetadata(default(bool)));
94+
95+
public static void SetIsIndicatorVisible(DependencyObject element, bool isIndicatorVisible)
96+
{
97+
element.SetValue(IsIndicatorVisibleProperty, isIndicatorVisible);
98+
}
99+
100+
public static bool GetIsIndicatorVisible(DependencyObject element)
101+
{
102+
return (bool)element.GetValue(IndicatorForegroundProperty);
103+
}
78104
}
79105
}

0 commit comments

Comments
 (0)