Skip to content

Commit 646b11f

Browse files
committed
Merge pull request #14 from ButchersBoy/master
update from original repo
2 parents 688c764 + 3c30be7 commit 646b11f

12 files changed

+97
-37
lines changed

MainDemo.Wpf/Buttons.xaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,22 @@
167167
ToolTip="Resource name: MaterialDesignRaisedAccentButton">
168168
ACCENT
169169
</Button>
170-
171170
</StackPanel>
172171
<StackPanel Grid.Row="3" Margin="0 24 0 0" Orientation="Horizontal">
173172
<Button Style="{StaticResource MaterialDesignRaisedAccentButton}"
174173
Margin="0 0 8 0"
175174
Width="150"
176175
ToolTip="Resource name: MaterialDesignRaisedAccentButton"
177176
materialDesign:RippleAssist.Feedback="#DD000000">CUSTOM RIPPLE</Button>
177+
<Button Style="{StaticResource MaterialDesignRaisedAccentButton}"
178+
Margin="0 0 8 0"
179+
Width="150"
180+
ToolTip="Resource name: MaterialDesignRaisedAccentButton"
181+
materialDesign:RippleAssist.IsDisabled="True">NO RIPPLE</Button>
182+
<RepeatButton Margin="0 0 8 0" Width="100"
183+
ToolTip="Resource name: MaterialDesignRaisedButton">
184+
REPEAT
185+
</RepeatButton>
178186
<Button Style="{StaticResource MaterialDesignFlatButton}" Click="ButtonBase_OnClick" ToolTip="MaterialDesignFlatButton" Margin="200 0 0 0">ACCEPT</Button>
179187
<Button Style="{StaticResource MaterialDesignFlatButton}" ToolTip="MaterialDesignFlatButton">CANCEL</Button>
180188
</StackPanel>

MainDemo.Wpf/Pickers.xaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@
3535
</Binding>
3636
</DatePicker.SelectedDate>
3737
</DatePicker>
38+
<ComboBox Name="LocaleCombo" HorizontalAlignment="Left" Width="50" Margin="0 32 0 0">
39+
<ComboBox.ItemsPanel>
40+
<ItemsPanelTemplate>
41+
<VirtualizingStackPanel />
42+
</ItemsPanelTemplate>
43+
</ComboBox.ItemsPanel>
44+
</ComboBox>
45+
<DatePicker Name="LocaleDatePicker" Width="120" HorizontalAlignment="Left" Margin="0 16 0 0" materialDesign:HintAssist.Hint="Locale Date" />
46+
<DatePicker Name="LocaleDatePickerRTL" Width="120" HorizontalAlignment="Left" Margin="0 16 0 0" materialDesign:HintAssist.Hint="RTL Locale Date" FlowDirection="RightToLeft" />
3847
</StackPanel>
3948
<materialDesign:TimePicker Grid.Row="1" Grid.Column="1" VerticalAlignment="Top" Width="100" HorizontalAlignment="Left" Margin="0 16 0 0"
4049
Style="{StaticResource MaterialDesignFloatingHintTimePicker}"

MainDemo.Wpf/Pickers.xaml.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.Linq;
45
using System.Text;
56
using System.Threading.Tasks;
@@ -25,6 +26,32 @@ public Pickers()
2526
{
2627
InitializeComponent();
2728
FutureDatePicker.BlackoutDates.AddDatesInPast();
29+
LoadLocales();
30+
LocaleCombo.SelectionChanged += LocaleCombo_SelectionChanged;
31+
LocaleCombo.SelectedItem = "fr-CA";
32+
}
33+
34+
private void LocaleCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
35+
{
36+
var lang = System.Windows.Markup.XmlLanguage.GetLanguage((string)LocaleCombo.SelectedItem);
37+
LocaleDatePicker.Language = lang;
38+
LocaleDatePickerRTL.Language = lang;
39+
40+
//HACK: The calendar only refresh when we change the date
41+
LocaleDatePicker.DisplayDate = LocaleDatePicker.DisplayDate.AddDays(1);
42+
LocaleDatePicker.DisplayDate = LocaleDatePicker.DisplayDate.AddDays(-1);
43+
LocaleDatePickerRTL.DisplayDate = LocaleDatePicker.DisplayDate.AddDays(1);
44+
LocaleDatePickerRTL.DisplayDate = LocaleDatePicker.DisplayDate.AddDays(-1);
45+
}
46+
47+
private void LoadLocales()
48+
{
49+
foreach (var ci in CultureInfo.GetCultures(CultureTypes.AllCultures)
50+
.Where(ci => ci.Calendar is GregorianCalendar)
51+
.OrderBy(ci => ci.Name))
52+
{
53+
LocaleCombo.Items.Add(ci.Name);
54+
}
2855
}
2956

3057
public void CalendarDialogOpenedEventHandler(object sender, DialogOpenedEventArgs eventArgs)

MaterialDesignThemes.Wpf/MaterialDateDisplay.cs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,13 @@ namespace MaterialDesignThemes.Wpf
1818
{
1919
public class MaterialDateDisplay : Control
2020
{
21-
private readonly IDictionary<int, Action<string>> _setters;
22-
private readonly IDictionary<char, string> _formats = new Dictionary<char, string>
23-
{
24-
{'d', "dd"},
25-
{'m', "ddd, MMM"},
26-
{'y', "yyyy"}
27-
};
28-
2921
static MaterialDateDisplay()
3022
{
3123
DefaultStyleKeyProperty.OverrideMetadata(typeof(MaterialDateDisplay), new FrameworkPropertyMetadata(typeof(MaterialDateDisplay)));
3224
}
3325

3426
public MaterialDateDisplay()
3527
{
36-
_setters = new Dictionary<int, Action<string>>
37-
{
38-
{0, s => ComponentOneContent = s},
39-
{1, s => ComponentTwoContent = s},
40-
{2, s => ComponentThreeContent = s},
41-
};
4228
SetCurrentValue(DisplayDateProperty, DateTime.Now.Date);
4329
}
4430

@@ -115,15 +101,12 @@ public bool IsDayInFirstComponent
115101
//FrameworkElement.LanguageProperty.OverrideMetadata(typeof (Calendar), (PropertyMetadata) new FrameworkPropertyMetadata(new PropertyChangedCallback(Calendar.OnLanguageChanged)));
116102
private void UpdateComponents()
117103
{
118-
var dateTimeFormatInfo = CultureInfo.CurrentUICulture.GetDateFormat();
104+
var culture = Language.GetSpecificCulture();
105+
var dateTimeFormatInfo = culture.GetDateFormat();
119106

120-
foreach (var component in dateTimeFormatInfo.ShortDatePattern.Split(new[] {dateTimeFormatInfo.DateSeparator},
121-
StringSplitOptions.RemoveEmptyEntries).Select((s, index) => new {code = s.ToLower()[0], index}))
122-
{
123-
if (component.index == 0)
124-
IsDayInFirstComponent = component.code == 'd';
125-
_setters[component.index](DisplayDate.ToString(_formats[component.code], CultureInfo.CurrentUICulture).ToTitleCase());
126-
}
107+
ComponentOneContent = DisplayDate.ToString(dateTimeFormatInfo.MonthDayPattern.Replace("MMMM", "MMM"), culture).ToTitleCase(culture); //Day Month folowing culture order. We don't want the month to take too much space
108+
ComponentTwoContent = DisplayDate.ToString("ddd,", culture).ToTitleCase(culture); // Day of week first
109+
ComponentThreeContent = DisplayDate.ToString("yyyy", culture).ToTitleCase(culture); // Year always top
127110
}
128111

129112
/// <summary>

MaterialDesignThemes.Wpf/PopupBox.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ private static void OnLostMouseCapture(object sender, MouseEventArgs e)
657657
}
658658
else
659659
{
660-
if (popupBox.StaysOpen)
660+
if (popupBox.StaysOpen && popupBox.IsPopupOpen)
661661
{
662662
// Take capture back because click happend outside of control
663663
Mouse.Capture(popupBox, CaptureMode.SubTree);

MaterialDesignThemes.Wpf/Ripple.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,12 @@ protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
118118
RippleY = point.Y - RippleSize / 2;
119119
}
120120

121-
VisualStateManager.GoToState(this, TemplateStateNormal, false);
122-
VisualStateManager.GoToState(this, TemplateStateMousePressed, true);
123-
PressedInstances.Add(this);
121+
if (!RippleAssist.GetIsDisabled(this))
122+
{
123+
VisualStateManager.GoToState(this, TemplateStateNormal, false);
124+
VisualStateManager.GoToState(this, TemplateStateMousePressed, true);
125+
PressedInstances.Add(this);
126+
}
124127

125128
base.OnPreviewMouseLeftButtonDown(e);
126129
}

MaterialDesignThemes.Wpf/RippleAssist.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,35 @@ public static bool GetIsCentered(DependencyObject element)
5454

5555
#endregion
5656

57+
#region disable
58+
59+
/// <summary>
60+
/// Set to <c>True</c> to disable ripple effect
61+
/// </summary>
62+
public static readonly DependencyProperty IsDisabledProperty = DependencyProperty.RegisterAttached(
63+
"IsDisabled", typeof(bool), typeof(RippleAssist), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.Inherits));
64+
65+
/// <summary>
66+
/// Set to <c>True</c> to disable ripple effect
67+
/// </summary>
68+
/// <param name="element"></param>
69+
/// <param name="value"></param>
70+
public static void SetIsDisabled(DependencyObject element, bool value)
71+
{
72+
element.SetValue(IsDisabledProperty, value);
73+
}
74+
75+
/// <summary>
76+
/// Set to <c>True</c> to disable ripple effect
77+
/// </summary>
78+
/// <param name="element"></param>
79+
public static bool GetIsDisabled(DependencyObject element)
80+
{
81+
return (bool)element.GetValue(IsDisabledProperty);
82+
}
83+
84+
#endregion
85+
5786
#region RippleSizeMultiplier
5887

5988
public static readonly DependencyProperty RippleSizeMultiplierProperty = DependencyProperty.RegisterAttached(

MaterialDesignThemes.Wpf/StringExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ namespace MaterialDesignThemes.Wpf
99
{
1010
internal static class StringExtensions
1111
{
12-
public static string ToTitleCase(this string text, string separator = " ")
12+
public static string ToTitleCase(this string text, CultureInfo culture, string separator = " ")
1313
{
14-
TextInfo textInfo = CultureInfo.CurrentUICulture.TextInfo;
14+
TextInfo textInfo = culture.TextInfo;
1515

1616
string lowerText = textInfo.ToLower(text);
1717
string[] words = lowerText.Split(new[] { separator }, StringSplitOptions.None);

MaterialDesignThemes.Wpf/Themes/Generic.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,8 +850,8 @@
850850
</Setter>
851851
</Style>
852852

853-
<Style TargetType="{x:Type transitions:TransitioningContentBase}">
854-
853+
<Style TargetType="{x:Type transitions:TransitioningContentBase}">
854+
<Setter Property="KeyboardNavigation.IsTabStop" Value="False"/>
855855
<Setter Property="Template">
856856
<Setter.Value>
857857
<ControlTemplate TargetType="{x:Type transitions:TransitioningContentBase}">

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Button.xaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
<SolidColorBrush x:Key="AttentionToActionBrush" Color="{StaticResource MaterialDesignShadow}" Opacity=".23" po:Freeze="True" />
2222

23-
<Style x:Key="MaterialDesignRaisedButton" TargetType="{x:Type Button}">
23+
<Style x:Key="MaterialDesignRaisedButton" TargetType="{x:Type ButtonBase}">
2424
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
2525
<Setter Property="Background" Value="{DynamicResource PrimaryHueMidBrush}"/>
2626
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryHueMidBrush}"/>
@@ -37,7 +37,7 @@
3737
<Setter Property="Height" Value="32" />
3838
<Setter Property="Template">
3939
<Setter.Value>
40-
<ControlTemplate TargetType="{x:Type Button}">
40+
<ControlTemplate TargetType="{x:Type ButtonBase}">
4141
<Grid>
4242
<AdornerDecorator>
4343
<AdornerDecorator.CacheMode>
@@ -69,19 +69,19 @@
6969
</Setter>
7070
</Style>
7171

72-
<Style x:Key="MaterialDesignRaisedLightButton" TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignRaisedButton}">
72+
<Style x:Key="MaterialDesignRaisedLightButton" TargetType="{x:Type ButtonBase}" BasedOn="{StaticResource MaterialDesignRaisedButton}">
7373
<Setter Property="Background" Value="{DynamicResource PrimaryHueLightBrush}"/>
7474
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryHueLightBrush}"/>
7575
<Setter Property="Foreground" Value="{DynamicResource PrimaryHueLightForegroundBrush}"/>
7676
</Style>
7777

78-
<Style x:Key="MaterialDesignRaisedDarkButton" TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignRaisedButton}">
78+
<Style x:Key="MaterialDesignRaisedDarkButton" TargetType="{x:Type ButtonBase}" BasedOn="{StaticResource MaterialDesignRaisedButton}">
7979
<Setter Property="Background" Value="{DynamicResource PrimaryHueDarkBrush}"/>
8080
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryHueDarkBrush}"/>
8181
<Setter Property="Foreground" Value="{DynamicResource PrimaryHueDarkForegroundBrush}"/>
8282
</Style>
8383

84-
<Style x:Key="MaterialDesignRaisedAccentButton" TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignRaisedButton}">
84+
<Style x:Key="MaterialDesignRaisedAccentButton" TargetType="{x:Type ButtonBase}" BasedOn="{StaticResource MaterialDesignRaisedButton}">
8585
<Setter Property="Background" Value="{DynamicResource SecondaryAccentBrush}"/>
8686
<Setter Property="BorderBrush" Value="{DynamicResource SecondaryAccentBrush}"/>
8787
<Setter Property="Foreground" Value="{DynamicResource SecondaryAccentForegroundBrush}"/>

0 commit comments

Comments
 (0)