Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / Controls / CalendarDateRange.cs / 1305600 / CalendarDateRange.cs
//----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//---------------------------------------------------------------------------
using System;
using System.ComponentModel;
namespace System.Windows.Controls
{
///
/// Specifies a DateTime range class which has a start and end.
///
public sealed class CalendarDateRange : INotifyPropertyChanged
{
#region Data
private DateTime _end;
private DateTime _start;
#endregion Data
///
/// Initializes a new instance of the CalendarDateRange class.
///
public CalendarDateRange() :
this(DateTime.MinValue, DateTime.MaxValue)
{
}
///
/// Initializes a new instance of the CalendarDateRange class which creates a range from a single DateTime value.
///
///
public CalendarDateRange(DateTime day) :
this(day, day)
{
}
///
/// Initializes a new instance of the CalendarDateRange class which accepts range start and end dates.
///
///
///
public CalendarDateRange(DateTime start, DateTime end)
{
_start = start;
_end = end;
}
#region Public Events
public event PropertyChangedEventHandler PropertyChanged;
#endregion
#region Public Properties
///
/// Specifies the End date of the CalendarDateRange.
///
public DateTime End
{
get
{
return CoerceEnd(_start, _end);
}
set
{
DateTime newEnd = CoerceEnd(_start, value);
if (newEnd != End)
{
OnChanging(new CalendarDateRangeChangingEventArgs(_start, newEnd));
_end = value;
OnPropertyChanged(new PropertyChangedEventArgs("End"));
}
}
}
///
/// Specifies the Start date of the CalendarDateRange.
///
public DateTime Start
{
get
{
return _start;
}
set
{
if (_start != value)
{
DateTime oldEnd = End;
DateTime newEnd = CoerceEnd(value, _end);
OnChanging(new CalendarDateRangeChangingEventArgs(value, newEnd));
_start = value;
OnPropertyChanged(new PropertyChangedEventArgs("Start"));
if (newEnd != oldEnd)
{
OnPropertyChanged(new PropertyChangedEventArgs("End"));
}
}
}
}
#endregion Public Properties
#region Internal Events
internal event EventHandler Changing;
#endregion Internal Events
#region Internal Methods
///
/// Returns true if any day in the given DateTime range is contained in the current CalendarDateRange.
///
///
///
internal bool ContainsAny(CalendarDateRange range)
{
return (range.End >= this.Start) && (this.End >= range.Start);
}
#endregion Internal Methods
#region Private Methods
private void OnChanging(CalendarDateRangeChangingEventArgs e)
{
EventHandler handler = this.Changing;
if (handler != null)
{
handler(this, e);
}
}
private void OnPropertyChanged(PropertyChangedEventArgs e)
{
PropertyChangedEventHandler handler = this.PropertyChanged;
if (handler != null)
{
handler(this, e);
}
}
///
/// Coerced the end parameter to satisfy the start <= end constraint
///
///
///
/// If start <= end the end parameter otherwise the start parameter
private static DateTime CoerceEnd(DateTime start, DateTime end)
{
return (DateTime.Compare(start, end) <= 0) ? end : start;
}
#endregion Private Methods
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//---------------------------------------------------------------------------
using System;
using System.ComponentModel;
namespace System.Windows.Controls
{
///
/// Specifies a DateTime range class which has a start and end.
///
public sealed class CalendarDateRange : INotifyPropertyChanged
{
#region Data
private DateTime _end;
private DateTime _start;
#endregion Data
///
/// Initializes a new instance of the CalendarDateRange class.
///
public CalendarDateRange() :
this(DateTime.MinValue, DateTime.MaxValue)
{
}
///
/// Initializes a new instance of the CalendarDateRange class which creates a range from a single DateTime value.
///
///
public CalendarDateRange(DateTime day) :
this(day, day)
{
}
///
/// Initializes a new instance of the CalendarDateRange class which accepts range start and end dates.
///
///
///
public CalendarDateRange(DateTime start, DateTime end)
{
_start = start;
_end = end;
}
#region Public Events
public event PropertyChangedEventHandler PropertyChanged;
#endregion
#region Public Properties
///
/// Specifies the End date of the CalendarDateRange.
///
public DateTime End
{
get
{
return CoerceEnd(_start, _end);
}
set
{
DateTime newEnd = CoerceEnd(_start, value);
if (newEnd != End)
{
OnChanging(new CalendarDateRangeChangingEventArgs(_start, newEnd));
_end = value;
OnPropertyChanged(new PropertyChangedEventArgs("End"));
}
}
}
///
/// Specifies the Start date of the CalendarDateRange.
///
public DateTime Start
{
get
{
return _start;
}
set
{
if (_start != value)
{
DateTime oldEnd = End;
DateTime newEnd = CoerceEnd(value, _end);
OnChanging(new CalendarDateRangeChangingEventArgs(value, newEnd));
_start = value;
OnPropertyChanged(new PropertyChangedEventArgs("Start"));
if (newEnd != oldEnd)
{
OnPropertyChanged(new PropertyChangedEventArgs("End"));
}
}
}
}
#endregion Public Properties
#region Internal Events
internal event EventHandler Changing;
#endregion Internal Events
#region Internal Methods
///
/// Returns true if any day in the given DateTime range is contained in the current CalendarDateRange.
///
///
///
internal bool ContainsAny(CalendarDateRange range)
{
return (range.End >= this.Start) && (this.End >= range.Start);
}
#endregion Internal Methods
#region Private Methods
private void OnChanging(CalendarDateRangeChangingEventArgs e)
{
EventHandler handler = this.Changing;
if (handler != null)
{
handler(this, e);
}
}
private void OnPropertyChanged(PropertyChangedEventArgs e)
{
PropertyChangedEventHandler handler = this.PropertyChanged;
if (handler != null)
{
handler(this, e);
}
}
///
/// Coerced the end parameter to satisfy the start <= end constraint
///
///
///
/// If start <= end the end parameter otherwise the start parameter
private static DateTime CoerceEnd(DateTime start, DateTime end)
{
return (DateTime.Compare(start, end) <= 0) ? end : start;
}
#endregion Private Methods
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SwitchLevelAttribute.cs
- ImageSource.cs
- ScalarType.cs
- RootProfilePropertySettingsCollection.cs
- IWorkflowDebuggerService.cs
- TypeInfo.cs
- keycontainerpermission.cs
- AssociationEndMember.cs
- SelectionRange.cs
- Html32TextWriter.cs
- InputEventArgs.cs
- ModifierKeysConverter.cs
- PeerNearMe.cs
- WebServiceFaultDesigner.cs
- LazyTextWriterCreator.cs
- AutoFocusStyle.xaml.cs
- CultureSpecificStringDictionary.cs
- XmlnsDictionary.cs
- DataSourceProvider.cs
- BCLDebug.cs
- DataGridViewHitTestInfo.cs
- EntityDataSourceConfigureObjectContext.cs
- WpfWebRequestHelper.cs
- DrawingBrush.cs
- XPathDocumentBuilder.cs
- VariantWrapper.cs
- HttpCapabilitiesEvaluator.cs
- TreeNodeStyleCollection.cs
- DropDownList.cs
- SizeAnimationUsingKeyFrames.cs
- httpapplicationstate.cs
- CursorConverter.cs
- DataColumn.cs
- SqlBulkCopy.cs
- CompilerState.cs
- GlyphingCache.cs
- ListViewSelectEventArgs.cs
- SafeNativeMethods.cs
- CommonDialog.cs
- DtdParser.cs
- ShapeTypeface.cs
- CodeTypeConstructor.cs
- Literal.cs
- StringInfo.cs
- DescendentsWalker.cs
- DashStyles.cs
- ResolveCriteriaCD1.cs
- COM2ExtendedTypeConverter.cs
- X509Certificate2Collection.cs
- MDIClient.cs
- FlowNode.cs
- DeclarativeCatalogPart.cs
- StrokeCollection.cs
- MethodCallTranslator.cs
- PreservationFileWriter.cs
- EnterpriseServicesHelper.cs
- ExtensionDataReader.cs
- CheckoutException.cs
- BounceEase.cs
- Vector3DAnimationBase.cs
- ScanQueryOperator.cs
- UnsafeNativeMethods.cs
- AtomParser.cs
- SchemaTableOptionalColumn.cs
- LongValidatorAttribute.cs
- ExpressionPrinter.cs
- FileLoadException.cs
- SqlBulkCopyColumnMappingCollection.cs
- UnicodeEncoding.cs
- CapabilitiesPattern.cs
- Compiler.cs
- TcpAppDomainProtocolHandler.cs
- TypeDescriptionProviderAttribute.cs
- ShaderEffect.cs
- RuleSetDialog.Designer.cs
- GridPattern.cs
- MouseEvent.cs
- GeometryHitTestParameters.cs
- CategoryGridEntry.cs
- QilSortKey.cs
- DeferredSelectedIndexReference.cs
- FormsAuthenticationEventArgs.cs
- Section.cs
- URLMembershipCondition.cs
- DataGridViewSelectedColumnCollection.cs
- LookupNode.cs
- TextEditorTables.cs
- EditingMode.cs
- BigIntegerStorage.cs
- SqlBulkCopy.cs
- ClientRoleProvider.cs
- MenuBase.cs
- Application.cs
- MergeLocalizationDirectives.cs
- RotateTransform.cs
- DataServiceProcessingPipelineEventArgs.cs
- LineBreakRecord.cs
- CopyOnWriteList.cs
- ThemeDirectoryCompiler.cs
- HtmlForm.cs