Skip to content

Commit 5ec133d

Browse files
committed
Added minimum and maximum visible interval to TimeControl.
1 parent 9962538 commit 5ec133d

5 files changed

Lines changed: 34 additions & 4 deletions

File tree

Binary file not shown.
Binary file not shown.

Whathecode.TimeLine/Themes/Generic.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
<Setter.Value>
3232
<ItemsPanelTemplate>
3333
<wtc:TimePanel
34+
MinimumSizeX="{Binding MinimumInterval, RelativeSource={RelativeSource AncestorType=controls:TimeControl}}"
35+
MaximumSizeX="{Binding MaximumInterval, RelativeSource={RelativeSource AncestorType=controls:TimeControl}}"
3436
VisibleIntervalX="{Binding VisibleInterval, RelativeSource={RelativeSource AncestorType=controls:TimeControl}}" />
3537
</ItemsPanelTemplate>
3638
</Setter.Value>
@@ -75,6 +77,8 @@
7577
<wtc:TimePanel
7678
x:Name="PART_Labels"
7779
LabelFactories="{TemplateBinding LabelFactories}"
80+
MinimumSizeX="{TemplateBinding MinimumInterval}"
81+
MaximumSizeX="{TemplateBinding MaximumInterval}"
7882
VisibleIntervalX="{TemplateBinding VisibleInterval}" />
7983
</Border>
8084
<!-- ItemsSource elements -->

Whathecode.TimeLine/TimeControl.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public class TimeControl : ItemsControl
1313
public enum Properties
1414
{
1515
VisibleInterval,
16+
MinimumInterval,
17+
MaximumInterval,
1618
CurrentTime
1719
}
1820

@@ -37,6 +39,8 @@ public object GetDefaultValue( Properties property, Type propertyType )
3739
static readonly Type Type = typeof( TimeControl );
3840
public static DependencyPropertyFactory<Properties> PropertyFactory = new DependencyPropertyFactory<Properties>();
3941
public static DependencyProperty VisibleIntervalProperty = PropertyFactory[ Properties.VisibleInterval ];
42+
public static readonly DependencyProperty MinimumIntervalProperty = PropertyFactory[ Properties.MinimumInterval ];
43+
public static readonly DependencyProperty MaximumIntervalProperty = PropertyFactory[ Properties.MaximumInterval ];
4044
public static readonly DependencyProperty CurrentTimeProperty = PropertyFactory[ Properties.CurrentTime ];
4145

4246
[DependencyProperty( Properties.VisibleInterval, DefaultValueProvider = typeof( DefaultProvider ) )]
@@ -46,6 +50,20 @@ public Interval<DateTime, TimeSpan> VisibleInterval
4650
set { PropertyFactory.SetValue( this, Properties.VisibleInterval, value ); }
4751
}
4852

53+
[DependencyProperty( Properties.MinimumInterval, DefaultValue = "00:30:00" )]
54+
public TimeSpan MinimumInterval
55+
{
56+
get { return (TimeSpan)PropertyFactory.GetValue( this, Properties.MinimumInterval ); }
57+
set { PropertyFactory.SetValue( this, Properties.MinimumInterval, value ); }
58+
}
59+
60+
[DependencyProperty( Properties.MaximumInterval, DefaultValue = "650.00:00:00")]
61+
public TimeSpan MaximumInterval
62+
{
63+
get { return (TimeSpan)PropertyFactory.GetValue( this, Properties.MaximumInterval ); }
64+
set { PropertyFactory.SetValue( this, Properties.MaximumInterval, value ); }
65+
}
66+
4967
[DependencyProperty( Properties.CurrentTime )]
5068
public DateTime CurrentTime
5169
{

Whathecode.TimeLine/TimeLine.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using System.Windows;
44
using Whathecode.System;
5+
using Whathecode.System.Arithmetic.Range;
56
using Whathecode.System.Linq;
67
using Whathecode.System.Windows.Controls;
78
using Whathecode.System.Windows.DependencyPropertyFactory;
@@ -29,6 +30,8 @@ public enum TimeLineProperties
2930
public static readonly DependencyProperty DominantHeaderFactoryProperty = Factory[ TimeLineProperties.DominantHeaderFactory ];
3031
public static readonly DependencyProperty DominantBreadcrumbFactoryProperty = Factory[ TimeLineProperties.DominantBreadcrumbFactory ];
3132

33+
TimePanel _timePanel;
34+
3235

3336
[DependencyProperty( TimeLineProperties.LabelFactories )]
3437
public TimeLineLabelFactories LabelFactories
@@ -62,9 +65,9 @@ public string DominantBreadcrumbFactory
6265
static TimeLine()
6366
{
6467
DefaultStyleKeyProperty.OverrideMetadata( Type, new FrameworkPropertyMetadata( Type ) );
65-
VisibleIntervalProperty.AddOwner( typeof( TimeLine ) );
6668
}
6769

70+
6871
public TimeLine()
6972
{
7073
// TODO: Could intervals be specified in style, and factory instances initialized in code behind?
@@ -106,14 +109,14 @@ public override void OnApplyTemplate()
106109
{
107110
base.OnApplyTemplate();
108111

109-
TimePanel panel = (TimePanel)GetTemplateChild( "PART_Labels" );
110-
if ( panel == null )
112+
_timePanel = (TimePanel)GetTemplateChild( "PART_Labels" );
113+
if ( _timePanel == null )
111114
{
112115
return;
113116
}
114117

115118
// Identify the dominant labels before they are displayed.
116-
panel.LayoutUpdated += ( sender, args ) =>
119+
_timePanel.LayoutUpdated += ( sender, args ) =>
117120
{
118121
if ( LabelFactories != null )
119122
{
@@ -145,5 +148,10 @@ public override void OnApplyTemplate()
145148
}
146149
};
147150
}
151+
152+
public Interval<DateTime, TimeSpan> GetCoercedVisibleInterval()
153+
{
154+
return _timePanel != null ? _timePanel.VisibleIntervalX : VisibleInterval;
155+
}
148156
}
149157
}

0 commit comments

Comments
 (0)