Scheduler for WPF and Silverlight | ComponentOne
Scheduler for Silverlight Tutorials / Creating a Custom View / Step 3 of 4: Adding the Code to Control the Application
In This Topic
    Step 3 of 4: Adding the Code to Control the Application
    In This Topic

    In  this step you will add the C# or Visual Basic code that will control the application.

    1. Right-click the application and choose View Code from the list. Add the following namespace to the top of the page:

      Visual Basic
      Copy Code
      Imports C1.Silverlight.Schedule
      
      C#
      Copy Code
      using C1.Silverlight.Schedule;
      

    2. Add the following IDisposable Implementation to the Public Partial Class:        

      Visual Basic
      Copy Code
      Partial Public Class MainPage
         Inherits UserControl
               Implements IDisposable
      
      C#
      Copy Code
      public partial class MainPage : UserControl, IDisposable
      

    3. Insert the following code directly under the InitializeComponent() method:

      Visual Basic
      Copy Code
      sched1.ChangeStyle(sched1.WeekStyle)
          End Sub
          Private Sub btnToday_Click(sender As Object, e As C1.Silverlight.SourcedEventArgs)
              sched1.VisibleDates.BeginUpdate()
              sched1.VisibleDates.Clear()
              sched1.VisibleDates.Add(DateTime.Today)
              sched1.VisibleDates.EndUpdate()
          End Sub
          ' Change view from Month View mode to 2 Week mode if selection
          ' contains 2 full weeks.
          Private Sub sched1_BeforeViewChange(sender As Object, e As BeforeViewChangeEventArgs)
              If e.Dates.Length = 14 AndAlso e.Style Is sched1.MonthStyle Then
                  Dim s As Style = DirectCast(Me.Resources("TwoWeekStyle"), Style)
                  If s IsNot Nothing Then
                      e.Style = s
                  End If
              End If
          End Sub
          Private Sub btnDay_Click(sender As Object, e As C1.Silverlight.SourcedEventArgs)
              sched1.ChangeStyle(sched1.OneDayStyle)
          End Sub
          Private Sub btnWorkWeek_Click(sender As Object, e As C1.Silverlight.SourcedEventArgs)
              sched1.ChangeStyle(sched1.WorkingWeekStyle)
          End Sub
          Private Sub btnWeek_Click(sender As Object, e As C1.Silverlight.SourcedEventArgs)
              sched1.ChangeStyle(sched1.WeekStyle)
          End Sub
          Private Sub btn2Week_Click(sender As Object, e As C1.Silverlight.SourcedEventArgs)
              sched1.ChangeStyle(Resources("TwoWeekStyle"))
          End Sub
          Private Sub btnMonth_Click(sender As Object, e As C1.Silverlight.SourcedEventArgs)
              sched1.ChangeStyle(sched1.MonthStyle)
          End Sub
          Private Sub btnTimeLine_Click(sender As Object, e As C1.Silverlight.SourcedEventArgs)
              sched1.ChangeStyle(sched1.TimeLineStyle)
          End Sub
          Private Sub btnImport_Click(sender As Object, e As C1.Silverlight.SourcedEventArgs)
              C1Scheduler.ImportCommand.Execute(Nothing, sched1)
          End Sub
          Private Sub btnExport_Click(sender As Object, e As C1.Silverlight.SourcedEventArgs)
              C1Scheduler.ExportCommand.Execute(Nothing, sched1)
          End Sub
      #Region "IDisposable Support"
          Private disposedValue As Boolean ' To detect redundant calls
          ' IDisposable
          Protected Overridable Sub Dispose(disposing As Boolean)
              If Not Me.disposedValue Then
                  If disposing Then
                      ' TODO: dispose managed state (managed objects).
                  End If
                  ' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below.
                  ' TODO: set large fields to null.
              End If
              Me.disposedValue = True
          End Sub
      

      C#
      Copy Code
      sched1.ChangeStyle(sched1.WeekStyle);
              }
              private void btnToday_Click(object sender, C1.Silverlight.SourcedEventArgs e)
              {
                  sched1.VisibleDates.BeginUpdate();
                  sched1.VisibleDates.Clear();
                  sched1.VisibleDates.Add(DateTime.Today);
                  sched1.VisibleDates.EndUpdate();
              }
              // Change view from Month View mode to 2 Week mode if selection
              // contains 2 full weeks.
              void sched1_BeforeViewChange(object sender, BeforeViewChangeEventArgs e)
              {
                  if (e.Dates.Length == 14 && e.Style == sched1.MonthStyle)
                  {
                      Style s = (Style)this.Resources["TwoWeekStyle"];
                      if (s != null)
                      {
                          e.Style = s;
                      }
                  }
              }
              private void btnDay_Click(object sender, C1.Silverlight.SourcedEventArgs e)
              {
                  sched1.ChangeStyle(sched1.OneDayStyle);
              }
      
              private void btnWorkWeek_Click(object sender, C1.Silverlight.SourcedEventArgs e)
              {
                  sched1.ChangeStyle(sched1.WorkingWeekStyle);
              }
              private void btnWeek_Click(object sender, C1.Silverlight.SourcedEventArgs e)
              {
                  sched1.ChangeStyle(sched1.WeekStyle);
              }
              private void btn2Week_Click(object sender, C1.Silverlight.SourcedEventArgs e)
              {
                  sched1.ChangeStyle(Resources["TwoWeekStyle"]);
              }
              private void btnMonth_Click(object sender, C1.Silverlight.SourcedEventArgs e)
              {
                  sched1.ChangeStyle(sched1.MonthStyle);
              }
              private void btnTimeLine_Click(object sender, C1.Silverlight.SourcedEventArgs e)
              {
                  sched1.ChangeStyle(sched1.TimeLineStyle);
              }
              private void btnImport_Click(object sender, C1.Silverlight.SourcedEventArgs e)
              {
                  C1Scheduler.ImportCommand.Execute(null, sched1);
              }
              private void btnExport_Click(object sender, C1.Silverlight.SourcedEventArgs e)
              {
                  C1Scheduler.ExportCommand.Execute(null, sched1);
              }
      

    4. Add the code below to handle the IDisposable implementation. The Visual Basic code should be added automatically by Visual Studio:

      Visual Basic
      Copy Code
      #Region "IDisposable Support"
          Private disposedValue As Boolean ' To detect redundant calls
          ' IDisposable
          Protected Overridable Sub Dispose(disposing As Boolean)
              If Not Me.disposedValue Then
                  If disposing Then
                      sched1.Dispose()
                  End If
                  ' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below.
                  ' TODO: set large fields to null.
              End If
              Me.disposedValue = True
          End Sub
          ' TODO: override Finalize() only if Dispose(ByVal disposing As Boolean) above has code to free unmanaged resources.
          'Protected Overrides Sub Finalize()
          '    ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
          '    Dispose(False)
          '    MyBase.Finalize()
          'End Sub
          ' This code added by Visual Basic to correctly implement the disposable pattern.
          Public Sub Dispose() Implements IDisposable.Dispose
              ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
              Dispose(True)
              GC.SuppressFinalize(Me)
          End Sub
      

      C#
      Copy Code
      public void Dispose()
              {
                  sched1.Dispose();
              }