Skip to content

Commit 404e768

Browse files
committed
fix merge conflict
2 parents 560610b + e895ca3 commit 404e768

10 files changed

+405
-55
lines changed

MainDemo.Wpf/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
TextOptions.TextFormattingMode="Ideal"
1313
TextOptions.TextRenderingMode="Auto"
1414
Background="{DynamicResource MaterialDesignPaper}"
15-
FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto" Icon="favicon.ico">
15+
FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto" Icon="favicon.ico" WindowStartupLocation="CenterScreen" WindowState="Maximized">
1616
<Window.Resources>
1717
<ResourceDictionary>
1818
<ResourceDictionary.MergedDictionaries>

MainDemo.Wpf/TextFields.xaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
<RowDefinition Height="Auto" />
5252
<RowDefinition Height="Auto" />
5353
<RowDefinition Height="Auto" />
54-
<RowDefinition Height="Auto" />
54+
<RowDefinition Height="Auto" />
55+
<RowDefinition Height="Auto" />
5556
</Grid.RowDefinitions>
5657
<Viewbox Grid.Row="0" Grid.Column="0">
5758
<Canvas Width="24" Height="24">
@@ -145,13 +146,16 @@
145146
<wpf:TimePicker Grid.Row="5" Grid.Column="3" VerticalAlignment="Top" Width="100" HorizontalAlignment="Left" Margin="0 8 0 8"
146147
wpf:TextFieldAssist.Hint="Custom hint" />
147148
<wpf:TimePicker Grid.Row="5" Grid.Column="4" x:Name="PresetTimePicker" VerticalAlignment="Top" Width="100" HorizontalAlignment="Left" Margin="0 8 0 8" />
148-
<Slider Grid.Row="6" Grid.Column="1" TickFrequency="5" Orientation="Horizontal" Minimum="1" Maximum="50" Value="25" />
149+
150+
<wpf:TimePicker Is24Hours="True" Grid.Row="6" Grid.Column="1" x:Name="PresetTimePicker24" VerticalAlignment="Top" Width="100" HorizontalAlignment="Left" Margin="0 8 0 8" />
151+
152+
<Slider Grid.Row="7" Grid.Column="1" TickFrequency="5" Orientation="Horizontal" Minimum="1" Maximum="50" Value="25" />
149153
<StackPanel Orientation="Horizontal" Grid.Row="6" Grid.Column="3" Grid.RowSpan="3" >
150154
<Slider TickFrequency="5" TickPlacement="BottomRight" Orientation="Vertical" Minimum="1" Maximum="50" />
151155
<Slider TickFrequency="25" TickPlacement="TopLeft" Orientation="Vertical" Minimum="1" Maximum="50" IsEnabled="False" Margin="24 8 0 8" />
152156
</StackPanel>
153-
<Slider Grid.Row="7" Grid.Column="1" TickFrequency="5" Orientation="Horizontal" TickPlacement="BottomRight" Minimum="1" Maximum="50" Value="25" IsSelectionRangeEnabled="True" />
154-
<Slider Grid.Row="8" Grid.Column="1" TickFrequency="5" Orientation="Horizontal" TickPlacement="BottomRight" Minimum="1" Maximum="50" Value="25" IsEnabled="False" />
157+
<Slider Grid.Row="8" Grid.Column="1" TickFrequency="5" Orientation="Horizontal" TickPlacement="BottomRight" Minimum="1" Maximum="50" Value="25" IsSelectionRangeEnabled="True" />
158+
<Slider Grid.Row="9" Grid.Column="1" TickFrequency="5" Orientation="Horizontal" TickPlacement="BottomRight" Minimum="1" Maximum="50" Value="25" IsEnabled="False" />
155159

156160
</Grid>
157161
</UserControl>

MaterialDesignThemes.Wpf/Clock.cs

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,24 @@ public enum ClockDisplayAutomation
3232
}
3333

3434
[TemplatePart(Name = HoursCanvasPartName, Type = typeof (Canvas))]
35-
[TemplatePart(Name = MinutesCanvasPartName, Type = typeof(Canvas))]
35+
[TemplatePart(Name = MinutesCanvasPartName, Type = typeof(Canvas))]
3636
[TemplatePart(Name = MinuteReadOutPartName, Type = typeof(TextBlock))]
3737
[TemplatePart(Name = HourReadOutPartName, Type = typeof(TextBlock))]
38-
public class Clock : Control
38+
39+
[TemplatePart(Name = Hours13To00CanvasPartName, Type = typeof(Canvas))]
40+
[TemplatePart(Name = Hours1To12CanvasPartName, Type = typeof(Canvas))]
41+
[TemplatePart(Name = Minutes24HCanvasPartName, Type = typeof(Canvas))]
42+
public class Clock : Control
3943
{
4044
public const string HoursCanvasPartName = "PART_HoursCanvas";
41-
public const string MinutesCanvasPartName = "PART_MinutesCanvas";
45+
public const string MinutesCanvasPartName = "PART_MinutesCanvas";
4246
public const string MinuteReadOutPartName = "PART_MinuteReadOut";
4347
public const string HourReadOutPartName = "PART_HourReadOut";
4448

49+
public const string Hours13To00CanvasPartName = "PART_13To00HoursCanvas";
50+
public const string Hours1To12CanvasPartName = "PART_1To12HoursCanvas";
51+
public const string Minutes24HCanvasPartName = "PART_24HMinutesCanvas";
52+
4553
private Point _centreCanvas = new Point(0, 0);
4654
private Point _currentStartPosition = new Point(0, 0);
4755
private TextBlock _hourReadOutPartName;
@@ -92,6 +100,16 @@ public bool IsPostMeridiem
92100
set { SetValue(IsPostMeridiemProperty, value); }
93101
}
94102

103+
public static readonly DependencyProperty Is24HoursProperty = DependencyProperty.Register(
104+
"Is24Hours", typeof (bool), typeof (Clock), new PropertyMetadata(default(bool)));
105+
106+
public bool Is24Hours
107+
{
108+
get { return (bool) GetValue(Is24HoursProperty); }
109+
set { SetValue(Is24HoursProperty, value); }
110+
}
111+
112+
95113
public static readonly DependencyProperty DisplayModeProperty = DependencyProperty.Register(
96114
"DisplayMode", typeof (ClockDisplayMode), typeof (Clock), new PropertyMetadata(ClockDisplayMode.Hours));
97115

@@ -173,14 +191,27 @@ public override void OnApplyTemplate()
173191
{
174192
var hoursCanvas = GetTemplateChild(HoursCanvasPartName) as Canvas;
175193
if (hoursCanvas != null)
176-
GenerateButtons(hoursCanvas, Enumerable.Range(1, 12).ToList(), new ClockItemIsCheckedConverter(() => Time, ClockDisplayMode.Hours), i => "ButtonStyle");
194+
GenerateButtons(hoursCanvas, Enumerable.Range(1, 12).ToList(), new ClockItemIsCheckedConverter(() => Time, ClockDisplayMode.Hours, Is24Hours), i => "ButtonStyle");
177195

178196
var minutesCanvas = GetTemplateChild(MinutesCanvasPartName) as Canvas;
179197
if (minutesCanvas != null)
180-
GenerateButtons(minutesCanvas, Enumerable.Range(1, 60).ToList(), new ClockItemIsCheckedConverter(() => Time, ClockDisplayMode.Minutes),
198+
GenerateButtons(minutesCanvas, Enumerable.Range(1, 60).ToList(), new ClockItemIsCheckedConverter(() => Time, ClockDisplayMode.Minutes, Is24Hours),
181199
i => ((i / 5.0)%1) == 0.0 ? "ButtonStyle" : "LesserButtonStyle");
182200

183-
if (_hourReadOutPartName != null)
201+
var hours13To00Canvas = GetTemplateChild(Hours13To00CanvasPartName) as Canvas;
202+
if (hours13To00Canvas != null)
203+
GenerateButtons(hours13To00Canvas, new List<int> { 0, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, new ClockItemIsCheckedConverter(() => Time, ClockDisplayMode.Hours, Is24Hours), i => "ButtonStyle");
204+
205+
var hours1To12Canvas = GetTemplateChild(Hours1To12CanvasPartName) as Canvas;
206+
if (hours1To12Canvas != null)
207+
GenerateButtons(hours1To12Canvas, Enumerable.Range(1, 12).ToList(), new ClockItemIsCheckedConverter(() => Time, ClockDisplayMode.Hours, Is24Hours), i => "ButtonStyle");
208+
209+
var minutes24HCanvas = GetTemplateChild(Minutes24HCanvasPartName) as Canvas;
210+
if (minutes24HCanvas != null)
211+
GenerateButtons(minutes24HCanvas, Enumerable.Range(1, 60).ToList(), new ClockItemIsCheckedConverter(() => Time, ClockDisplayMode.Minutes, Is24Hours),
212+
i => ((i / 5.0) % 1) == 0.0 ? "ButtonStyle" : "LesserButtonStyle");
213+
214+
if (_hourReadOutPartName != null)
184215
_hourReadOutPartName.PreviewMouseLeftButtonDown -= HourReadOutPartNameOnPreviewMouseLeftButtonDown;
185216
if (_minuteReadOutPartName != null)
186217
_minuteReadOutPartName.PreviewMouseLeftButtonDown -= MinuteReadOutPartNameOnPreviewMouseLeftButtonDown;
@@ -223,7 +254,7 @@ private void GenerateButtons(Panel canvas, ICollection<int> range, IValueConvert
223254
var adjacent = Math.Cos(i*radiansPerItem)*hypotenuseRadius;
224255
var opposite = Math.Sin(i*radiansPerItem)*hypotenuseRadius;
225256

226-
button.CentreX = _centreCanvas.X + opposite;
257+
button.CentreX = _centreCanvas.X + opposite;
227258
button.CentreY = _centreCanvas.Y - adjacent;
228259

229260
button.SetBinding(ToggleButton.IsCheckedProperty, GetBinding("Time", converter: isCheckedConverter, converterParameter: i));
@@ -234,8 +265,9 @@ private void GenerateButtons(Panel canvas, ICollection<int> range, IValueConvert
234265
canvas.Children.Add(button);
235266
}
236267
}
268+
237269

238-
private void ClockItemDragCompletedHandler(object sender, DragCompletedEventArgs e)
270+
private void ClockItemDragCompletedHandler(object sender, DragCompletedEventArgs e)
239271
{
240272
OnClockChoiceMade(this, DisplayMode);
241273

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Windows;
3+
using System.Windows.Data;
4+
using System.Windows.Markup;
5+
6+
namespace MaterialDesignThemes.Wpf.Converters
7+
{
8+
public class BoolToVisibilityConverter : MarkupExtension, IValueConverter
9+
{
10+
public BoolToVisibilityConverter()
11+
{
12+
TrueValue = Visibility.Visible;
13+
FalseValue = Visibility.Collapsed;
14+
}
15+
16+
public Visibility TrueValue { get; set; }
17+
public Visibility FalseValue { get; set; }
18+
19+
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
20+
{
21+
bool val = System.Convert.ToBoolean(value);
22+
return val ? TrueValue : FalseValue;
23+
}
24+
25+
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
26+
{
27+
return TrueValue.Equals(value) ? true : false;
28+
}
29+
30+
public override object ProvideValue(IServiceProvider serviceProvider)
31+
{
32+
return this;
33+
}
34+
}
35+
}

MaterialDesignThemes.Wpf/Converters/ClockItemIsCheckedConverter.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,22 @@ internal class ClockItemIsCheckedConverter : IValueConverter
1313
{
1414
private readonly Func<DateTime> _currentTimeGetter;
1515
private readonly ClockDisplayMode _displayMode;
16+
private readonly bool _is24Hours;
1617

17-
public ClockItemIsCheckedConverter(Func<DateTime> currentTimeGetter, ClockDisplayMode displayMode)
18+
public ClockItemIsCheckedConverter(Func<DateTime> currentTimeGetter, ClockDisplayMode displayMode, bool is24Hours)
1819
{
1920
if (currentTimeGetter == null) throw new ArgumentNullException("currentTimeGetter");
2021

2122
_currentTimeGetter = currentTimeGetter;
2223
_displayMode = displayMode;
24+
_is24Hours = is24Hours;
2325
}
2426

2527
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
2628
{
2729
var dateTime = (DateTime) value;
2830
var i = (int) parameter;
29-
return (_displayMode == ClockDisplayMode.Hours ? MassageHour(dateTime.Hour) : MassageMinute(dateTime.Minute)) == i;
31+
return (_displayMode == ClockDisplayMode.Hours ? MassageHour(dateTime.Hour, _is24Hours) : MassageMinute(dateTime.Minute)) == i;
3032
}
3133

3234
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
@@ -37,13 +39,18 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
3739

3840
return new DateTime(
3941
currentTime.Year, currentTime.Month, currentTime.Day,
40-
(_displayMode == ClockDisplayMode.Hours) ? ReverseMassageHour((int)parameter, currentTime) : currentTime.Hour,
42+
(_displayMode == ClockDisplayMode.Hours) ? ReverseMassageHour((int)parameter, currentTime, _is24Hours) : currentTime.Hour,
4143
(_displayMode == ClockDisplayMode.Minutes) ? ReverseMassageMinute((int)parameter) : currentTime.Minute,
4244
currentTime.Second);
4345
}
4446

45-
private static int MassageHour(int val)
47+
private static int MassageHour(int val, bool is24Hours)
4648
{
49+
if (is24Hours)
50+
{
51+
return val;
52+
}
53+
4754
if (val == 0) return 12;
4855
if (val > 12) return val - 12;
4956
return val;
@@ -54,8 +61,13 @@ private static int MassageMinute(int val)
5461
return val == 0 ? 60 : val;
5562
}
5663

57-
private static int ReverseMassageHour(int val, DateTime currentTime)
64+
private static int ReverseMassageHour(int val, DateTime currentTime, bool is24Hours)
5865
{
66+
if (is24Hours)
67+
{
68+
return val;
69+
}
70+
5971
return currentTime.Hour < 12
6072
? (val == 12 ? 0 : val)
6173
: (val == 12 ? 12 : val + 12);
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
using System;
22
using System.Globalization;
33
using System.Windows.Data;
4+
using System.Windows.Markup;
45

56
namespace MaterialDesignThemes.Wpf.Converters
67
{
7-
public class ClockLineConverter : IValueConverter
8-
{
8+
public class ClockLineConverter : MarkupExtension, IValueConverter
9+
{
910
public ClockDisplayMode DisplayMode { get; set; }
1011

1112
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
1213
{
1314
var time = (DateTime) value;
14-
return DisplayMode == ClockDisplayMode.Hours
15-
? (time.Hour > 13 ? time.Hour - 12 : time.Hour)*(360/12)
15+
16+
return DisplayMode == ClockDisplayMode.Hours
17+
? ((time.Hour > 13) ? time.Hour - 12 : time.Hour)*(360/12)
1618
: (time.Minute == 0 ? 60 : time.Minute)*(360/60);
1719
}
1820

1921
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
2022
{
2123
return Binding.DoNothing;
2224
}
23-
}
25+
26+
public override object ProvideValue(IServiceProvider serviceProvider)
27+
{
28+
return this;
29+
}
30+
}
2431
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows;
4+
using System.Windows.Data;
5+
using System.Windows.Markup;
6+
7+
namespace MaterialDesignThemes.Wpf.Converters
8+
{
9+
public class TimeToVisibilityConverter: MarkupExtension, IValueConverter
10+
{
11+
public override object ProvideValue(IServiceProvider serviceProvider)
12+
{
13+
return this;
14+
}
15+
16+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
17+
{
18+
var time = (DateTime)value;
19+
20+
var isPm = ((time.Hour >= 13) || (time.Hour == 0));
21+
22+
return isPm ? Visibility.Visible : Visibility.Collapsed;
23+
}
24+
25+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
26+
{
27+
return Binding.DoNothing;
28+
}
29+
}
30+
}

MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@
204204
<Compile Include="ClockItemButton.cs" />
205205
<Compile Include="ColorZone.cs" />
206206
<Compile Include="Converters\BrushRoundConverter.cs" />
207+
<Compile Include="Converters\BoolToVisibilityConverter.cs" />
207208
<Compile Include="Converters\BrushToRadialGradientBrushConverter.cs" />
208209
<Compile Include="Converters\CalendarDateCoalesceConverter.cs" />
209210
<Compile Include="Converters\CircularProgressBar\ArcEndPointConverter.cs" />
@@ -221,6 +222,7 @@
221222
<Compile Include="Converters\NotZeroToVisibilityConverter.cs" />
222223
<Compile Include="Converters\ShadowConverter.cs" />
223224
<Compile Include="Converters\SizeToRectConverter.cs" />
225+
<Compile Include="Converters\TimeToVisibilityConverter.cs" />
224226
<Compile Include="CustomPopupPlacementCallbackHelper.cs" />
225227
<Compile Include="DataGridAssist.cs" />
226228
<Compile Include="DateTimeEx.cs" />

0 commit comments

Comments
 (0)