Skip to content

Commit b1b82d5

Browse files
author
BionicCode
committed
Improve ViewModel and Dialog
- Improved Dialog - Improved DialogViewModel. CanExecuteSendResponseCommand is now virtual. -Generic interface IAsyncRelayCommand<T> now implements IAsyncRelayCommand
1 parent c55e171 commit b1b82d5

File tree

93 files changed

+9605
-1360
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+9605
-1360
lines changed

BionicCode.Net/BionicCode.Controls.Net.Core.Wpf/BionicCode.Controls.Net.Core.Wpf.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp3.1;net48</TargetFrameworks>
4+
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
55
<UseWPF>true</UseWPF>
66
<ApplicationIcon>logo.ico</ApplicationIcon>
77
</PropertyGroup>

BionicCode.Net/BionicCode.Controls.Net.Framework.Wpf/BionicCalendar/Calendar.cs

Lines changed: 356 additions & 741 deletions
Large diffs are not rendered by default.

BionicCode.Net/BionicCode.Controls.Net.Framework.Wpf/BionicCalendar/CalendarPanel.cs

Lines changed: 609 additions & 262 deletions
Large diffs are not rendered by default.
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
#region Info
2+
3+
// 2021/02/12 11:52
4+
// BionicCode.Controls.Net.Framework.Wpf
5+
6+
#endregion
7+
8+
using System;
9+
using System.Collections;
10+
using System.Collections.Generic;
11+
using System.Globalization;
12+
using System.Linq;
13+
using System.Runtime.CompilerServices;
14+
15+
namespace BionicCode.Controls.Net.Framework.Wpf.BionicCalendar
16+
{
17+
public abstract class CalendarView
18+
{
19+
protected CalendarView(System.Globalization.Calendar calendar, DayOfWeek firstDayOfWeek)
20+
{
21+
this.Calendar = calendar;
22+
this.FirstDayOfWeek = firstDayOfWeek;
23+
}
24+
25+
public bool ContainsDate(DateTime date) => this.Dates.Contains(date);
26+
public virtual DateTime GetLastDate() => this.Dates.Last();
27+
public virtual DateTime GetFirstDate() => this.Dates.First();
28+
29+
public List<DateTime> Dates { get; protected set; }
30+
public DateTime Index { get; set; }
31+
public System.Globalization.Calendar Calendar { get; }
32+
public DayOfWeek FirstDayOfWeek { get; }
33+
}
34+
35+
public class CalendarWeekView : CalendarView
36+
{
37+
/// <inheritdoc />
38+
public CalendarWeekView(DateTime firstDateOfWeek, System.Globalization.Calendar calendar, DayOfWeek firstDayOfWeek) : base(calendar, firstDayOfWeek)
39+
{
40+
this.Dates = new List<DateTime>();
41+
this.WeekNumber = calendar.GetWeekOfYear(firstDateOfWeek, CalendarWeekRule.FirstFourDayWeek, firstDayOfWeek);
42+
}
43+
44+
public int WeekNumber { get; }
45+
}
46+
47+
public class CalendarMonthView : CalendarView, IEnumerator<CalendarWeekView>, IEnumerable<CalendarWeekView>
48+
{
49+
/// <inheritdoc />
50+
public CalendarMonthView(DateTime monthStart, System.Globalization.Calendar calendar, DayOfWeek firstDayOfWeek)
51+
: base(calendar, firstDayOfWeek)
52+
{
53+
this.Index = monthStart;
54+
this.Dates = CreateCalendarViewOfMonthDates(monthStart);
55+
this.CurrentIndex = -1;
56+
}
57+
58+
public CalendarMonthView GetPrevious() => CreateCalendarViewOfMonth(this.Index.AddMonths(-1));
59+
public CalendarMonthView GetNext() => CreateCalendarViewOfMonth(this.Index.AddMonths(1));
60+
61+
private CalendarMonthView CreateCalendarViewOfMonth(DateTime monthStart)
62+
{
63+
List<DateTime> datesOfCurrentView = CreateCalendarViewOfMonthDates(monthStart);
64+
var calendarView = new CalendarMonthView(monthStart, this.Calendar, this.FirstDayOfWeek) {Dates = datesOfCurrentView};
65+
66+
return calendarView;
67+
}
68+
69+
private List<DateTime> CreateCalendarViewOfMonthDates(DateTime monthStart)
70+
{
71+
var datesOfCurrentView = new List<DateTime>();
72+
DateTime firstDateInView = monthStart;
73+
int daysInMonth = this.Calendar.GetDaysInMonth(monthStart.Year, monthStart.Month);
74+
var lastDateInView = new DateTime(monthStart.Year, monthStart.Month, daysInMonth);
75+
76+
while (firstDateInView.DayOfWeek != this.FirstDayOfWeek)
77+
{
78+
firstDateInView = firstDateInView.Subtract(TimeSpan.FromDays(1));
79+
}
80+
81+
while (lastDateInView.AddDays(1).DayOfWeek != this.FirstDayOfWeek)
82+
{
83+
lastDateInView = lastDateInView.AddDays(1);
84+
}
85+
86+
int daysInCalendarView = lastDateInView.Subtract(firstDateInView).Days + 1;
87+
int requiredRowCount = (int) Math.Max(5, Math.Ceiling(daysInCalendarView / 7.0));
88+
int requiredDateCount = requiredRowCount * 7;
89+
90+
DateTime currentCalendarDate = firstDateInView;
91+
for (int dayIndex = 0;
92+
dayIndex < requiredDateCount;
93+
dayIndex++)
94+
{
95+
datesOfCurrentView.Add(currentCalendarDate.AddDays(dayIndex));
96+
}
97+
98+
return datesOfCurrentView;
99+
}
100+
101+
#region Implementation of IEnumerator
102+
103+
/// <inheritdoc />
104+
public bool MoveNext()
105+
{
106+
bool hasNext = ++this.CurrentIndex < Math.Ceiling(this.Dates.Count / 7.0);
107+
if (hasNext)
108+
{
109+
IEnumerable<DateTime> daysOfWeek = this.Dates.Skip(this.CurrentIndex * 7).Take(7).ToList();
110+
this.Current = new CalendarWeekView(daysOfWeek.FirstOrDefault(), this.Calendar, this.FirstDayOfWeek) {Index = daysOfWeek.FirstOrDefault()};
111+
this.Current.Dates.AddRange(daysOfWeek);
112+
}
113+
114+
return hasNext;
115+
}
116+
117+
/// <inheritdoc />
118+
public void Reset()
119+
{
120+
this.CurrentIndex = -1;
121+
this.Current = null;
122+
}
123+
124+
/// <inheritdoc />
125+
public CalendarWeekView Current { get; private set; }
126+
127+
/// <inheritdoc />
128+
object IEnumerator.Current => this.Current;
129+
130+
#endregion
131+
132+
private int CurrentIndex { get; set; }
133+
134+
public string Name => this.Index.ToString("MMMM", CultureInfo.CurrentCulture);
135+
136+
#region Overrides of Object
137+
138+
/// <inheritdoc />
139+
public override string ToString() => this.Name;
140+
141+
#endregion
142+
143+
#region IDisposable
144+
145+
/// <inheritdoc />
146+
public void Dispose()
147+
{
148+
}
149+
150+
#endregion
151+
152+
#region Implementation of IEnumerable
153+
154+
/// <inheritdoc />
155+
public IEnumerator<CalendarWeekView> GetEnumerator()
156+
{
157+
Reset();
158+
return this;
159+
}
160+
161+
/// <inheritdoc />
162+
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
163+
164+
#endregion
165+
166+
public int WeekCount => (int) Math.Ceiling(this.Dates.Count / 7.0);
167+
}
168+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#region Info
2+
3+
// 2021/02/18 13:43
4+
// BionicCode.Controls.Net.Framework.Wpf
5+
6+
#endregion
7+
8+
using System;
9+
using System.Windows;
10+
11+
namespace BionicCode.Controls.Net.Framework.Wpf.BionicCalendar
12+
{
13+
public class CalendarViewChangedEventArgs<TData> : RoutedEventArgs where TData : CalendarView
14+
{
15+
public CalendarViewChangedEventArgs(RoutedEvent routedEvent, TData currentView) : this(routedEvent, default, currentView)
16+
{
17+
}
18+
19+
public CalendarViewChangedEventArgs(RoutedEvent routedEvent, object source, TData currentView) : base(routedEvent, source)
20+
{
21+
this.CurrentView = currentView;
22+
}
23+
24+
public TData CurrentView { get; }
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#region Info
2+
3+
// 2021/02/18 13:43
4+
// BionicCode.Controls.Net.Framework.Wpf
5+
6+
#endregion
7+
8+
namespace BionicCode.Controls.Net.Framework.Wpf.BionicCalendar
9+
{
10+
public delegate void CalendarViewChangedRoutedEventHandler<TData>(object sender, CalendarViewChangedEventArgs<TData> e) where TData : CalendarView;
11+
}

BionicCode.Net/BionicCode.Controls.Net.Framework.Wpf/BionicCalendar/DateGeneratorArgs.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,34 @@ public class DateGeneratorArgs : EventArgs
1919
{
2020
#region
2121

22-
public DateGeneratorArgs() : this(null, null, null, -1, -1)
22+
public DateGeneratorArgs() : this(null, null, null, -1, -1, 0)
2323
{
2424
}
2525

26-
public DateGeneratorArgs(UIElement itemContainer, Panel itemsHost, object item, int columnIndex, int rowIndex)
26+
public DateGeneratorArgs(
27+
UIElement itemContainer,
28+
Panel itemsHost,
29+
object item,
30+
int columnIndex,
31+
int rowIndex,
32+
int weekNumber)
2733
{
2834
this.ItemContainer = itemContainer;
2935
this.ItemsHost = itemsHost;
3036
this.Item = item;
3137
this.ColumnIndex = columnIndex;
3238
this.RowIndex = rowIndex;
39+
this.WeekNumber = weekNumber;
3340
}
3441

3542
#endregion
3643

3744
public bool IsCanceled { get; set; }
38-
public UIElement ItemContainer { get; }
39-
public Panel ItemsHost { get; }
40-
public object Item { get; }
45+
public UIElement ItemContainer { get; set; }
46+
public Panel ItemsHost { get; set; }
47+
public object Item { get; set; }
4148
public int ColumnIndex { get; set; }
4249
public int RowIndex { get; set; }
50+
public int WeekNumber { get; set; }
4351
}
4452
}

BionicCode.Net/BionicCode.Controls.Net.Framework.Wpf/BionicCalendar/EventGeneratorArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public EventGeneratorArgs() : this(null, null, null, -1, -1)
2323
}
2424

2525
public EventGeneratorArgs(UIElement itemContainer, Panel itemsHost, object item, int columnIndex, int rowIndex)
26-
: base(itemContainer, itemsHost, item, columnIndex, rowIndex)
26+
: base(itemContainer, itemsHost, item, columnIndex, rowIndex, 0)
2727
{
2828
}
2929

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#region Info
2+
3+
// 2021/02/17 21:29
4+
// BionicCode.Controls.Net.Framework.Wpf
5+
6+
#endregion
7+
8+
using System.Windows;
9+
using System.Windows.Controls;
10+
11+
namespace BionicCode.Controls.Net.Framework.Wpf.BionicCalendar
12+
{
13+
public class WeekHeaderItem : ContentControl
14+
{
15+
static WeekHeaderItem()
16+
{
17+
FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(typeof(WeekHeaderItem), new FrameworkPropertyMetadata(typeof(WeekHeaderItem)));
18+
}
19+
}
20+
}

BionicCode.Net/BionicCode.Controls.Net.Framework.Wpf/BionicCharts/CartesianChart/VirtualizingCartesianCanvas.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010

1111
namespace BionicCode.Controls.Net.Framework.Wpf.BionicCharts
1212
{
13-
internal enum ScrollDirection
14-
{
15-
Undefined = 0, Left, Top, Right, Bottom
16-
}
17-
1813
public class VirtualizingCartesianCanvas : VirtualizingPanel, IScrollInfo
1914
{
2015
#region XZoomFactor attached property

0 commit comments

Comments
 (0)