Skip to content

Commit 7532ff6

Browse files
committed
demo for progress on raised button
1 parent ef0b53e commit 7532ff6

File tree

4 files changed

+68
-9
lines changed

4 files changed

+68
-9
lines changed

MainDemo.Wpf/Buttons.xaml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:system="clr-namespace:System;assembly=mscorlib"
77
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
8+
xmlns:materialDesignConverters="clr-namespace:MaterialDesignThemes.Wpf.Converters;assembly=MaterialDesignThemes.Wpf"
89
xmlns:wpfExample="clr-namespace:MaterialDesignColors.WpfExample"
910
xmlns:domain="clr-namespace:MaterialDesignDemo.Domain"
1011
mc:Ignorable="d"
@@ -20,6 +21,8 @@
2021
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.TextBlock.xaml" />
2122
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ToggleButton.xaml" />
2223
</ResourceDictionary.MergedDictionaries>
24+
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
25+
<materialDesignConverters:BooleanToVisibilityConverter x:Key="InvertedBooleanToVisibilityConverter" TrueValue="Collapsed" FalseValue="Visible" />
2326
</ResourceDictionary>
2427
</UserControl.Resources>
2528
<Grid VerticalAlignment="Top">
@@ -217,13 +220,24 @@
217220
<Border Margin="0 16 0 0" BorderThickness="0 1 0 0" BorderBrush="{DynamicResource MaterialDesignDivider}" Grid.Row="4" />
218221

219222
<TextBlock Style="{StaticResource MaterialDesignHeadlineTextBlock}"
220-
Grid.Row="5" >Buttons - With Progress</TextBlock>
223+
Grid.Row="5" Margin="0 12 0 12">Buttons - With Progress</TextBlock>
221224
<StackPanel Grid.Row="6" >
222225
<Button Command="{Binding DismissComand}"
223226
Style="{StaticResource MaterialDesignRaisedButton}"
224-
materialDesign:ButtonAssist.Value="{Binding DismissButtonProgress}">
225-
DISMISS
227+
HorizontalAlignment="Left"
228+
materialDesign:ButtonAssist.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>
226234
</Button>
235+
<Grid Height="32"
236+
Visibility="{Binding ShowDismissButton, Converter={StaticResource InvertedBooleanToVisibilityConverter}}">
237+
<TextBlock Text="{Binding DemoRestartCountdownText}"
238+
VerticalAlignment="Center"
239+
/>
240+
</Grid>
227241
</StackPanel>
228242
<Border Margin="0 16 0 0" BorderThickness="0 1 0 0" BorderBrush="{DynamicResource MaterialDesignDivider}" Grid.Row="7" />
229243

MainDemo.Wpf/ButtonsViewModel.cs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,56 @@ public class ButtonsViewModel : INotifyPropertyChanged
1111
{
1212
private bool _showDismissButton;
1313
private double _dismissButtonProgress;
14+
private string _demoRestartCountdownText;
1415

1516
public ButtonsViewModel()
1617
{
1718
var autoStartingActionCountdownStart = DateTime.Now;
18-
DismissComand = new AnotherCommandImplementation(_ => { });
19+
var demoRestartCountdownComplete = DateTime.Now;
20+
var dismissRequested = false;
21+
DismissComand = new AnotherCommandImplementation(_ => dismissRequested = true);
1922
ShowDismissButton = true;
2023

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.
26+
//and then hide the button, do whatever action you want to do
2127
new DispatcherTimer(
2228
TimeSpan.FromMilliseconds(100),
2329
DispatcherPriority.Normal,
2430
new EventHandler((o, e) =>
2531
{
32+
if (dismissRequested)
33+
{
34+
ShowDismissButton = false;
35+
dismissRequested = false;
36+
demoRestartCountdownComplete = DateTime.Now.AddSeconds(3);
37+
DismissButtonProgress = 0;
38+
}
39+
2640
if (ShowDismissButton)
2741
{
28-
var totalDuration = autoStartingActionCountdownStart.AddSeconds(20).Ticks - autoStartingActionCountdownStart.Ticks;
42+
var totalDuration = autoStartingActionCountdownStart.AddSeconds(5).Ticks - autoStartingActionCountdownStart.Ticks;
2943
var currentDuration = DateTime.Now.Ticks - autoStartingActionCountdownStart.Ticks;
3044
var autoCountdownPercentComplete = 100.0 / totalDuration * currentDuration;
3145
DismissButtonProgress = autoCountdownPercentComplete;
46+
47+
if (DismissButtonProgress >= 100)
48+
{
49+
demoRestartCountdownComplete = DateTime.Now.AddSeconds(3);
50+
ShowDismissButton = false;
51+
UpdateDemoRestartCountdownText(demoRestartCountdownComplete, out _);
52+
}
3253
}
54+
else
55+
{
56+
UpdateDemoRestartCountdownText(demoRestartCountdownComplete, out bool isComplete);
57+
if (isComplete)
58+
{
59+
autoStartingActionCountdownStart = DateTime.Now;
60+
ShowDismissButton = true;
61+
}
62+
}
63+
3364
}), Dispatcher.CurrentDispatcher);
3465
}
3566

@@ -47,6 +78,20 @@ public double DismissButtonProgress
4778
set { this.MutateVerbose(ref _dismissButtonProgress, value, RaisePropertyChanged()); }
4879
}
4980

81+
public string DemoRestartCountdownText
82+
{
83+
get { return _demoRestartCountdownText; }
84+
private set { this.MutateVerbose(ref _demoRestartCountdownText, value, RaisePropertyChanged()); }
85+
}
86+
87+
private void UpdateDemoRestartCountdownText(DateTime endTime, out bool isComplete)
88+
{
89+
var span = endTime - DateTime.Now;
90+
var seconds = Math.Round(span.TotalSeconds < 0 ? 0 : span.TotalSeconds);
91+
DemoRestartCountdownText = "Demo in " + seconds;
92+
isComplete = seconds == 0;
93+
}
94+
5095
public event PropertyChangedEventHandler PropertyChanged;
5196

5297
private Action<PropertyChangedEventArgs> RaisePropertyChanged()

MaterialDesignThemes.Wpf/Converters/RangeLengthConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur
2222
var percent = (value - min) / (max - min);
2323
var length = percent * containerLength;
2424

25-
return length;
25+
return length > containerLength ? containerLength : length;
2626
}
2727

2828
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Button.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@
5151
<Border HorizontalAlignment="Left" Background="{DynamicResource MaterialDesignBackground}" Opacity=".4">
5252
<Border.Width>
5353
<MultiBinding Converter="{StaticResource RangeLengthConverter}">
54-
<Binding Path="wpf:ButtonAssist.Minumum" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type ButtonBase}}" />
55-
<Binding Path="wpf:ButtonAssist.Maximum" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type ButtonBase}}" />
56-
<Binding Path="wpf:ButtonAssist.Value" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type ButtonBase}}" />
54+
<Binding Path="(wpf:ButtonAssist.Minimum)" RelativeSource="{RelativeSource TemplatedParent}" />
55+
<Binding Path="(wpf:ButtonAssist.Maximum)" RelativeSource="{RelativeSource TemplatedParent}" />
56+
<Binding Path="(wpf:ButtonAssist.Value)" RelativeSource="{RelativeSource TemplatedParent}" />
5757
<Binding Path="ActualWidth" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type ButtonBase}}" />
5858
</MultiBinding>
5959
</Border.Width>

0 commit comments

Comments
 (0)