Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Busy/Free/On sickleave,etc (Read 3881 times)
yuri
YaBB Newbies
*
Offline



Posts: 3
Joined: May 12th, 2010
Busy/Free/On sickleave,etc
May 19th, 2010 at 9:16am
Print Post  
I'm currently evaluating Mindfusion.Scheduling.

I'm looking into a way to show that a Resource is busy/free/on sickleave, etc...

Something like this:


I've tried to do this using a custom resource template. Unfortunately I wasn't able to reach the stripe on the left of the cell. Is there any way to change the color of this stripe?
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Busy/Free/On sickleave,etc
Reply #1 - May 19th, 2010 at 10:45am
Print Post  
This can indeed be achieved with a custom cell template. Here is what you need to do:

1. Copy the following Style resource to an accessible location within your project.

[code]<Style x:Key="BusyCellStyle" TargetType="{x:Type p:CellPresenter}">
     <Style.Triggers>
           <DataTrigger Binding="{Binding StyleKey, RelativeSource={RelativeSource Self}}" Value="Simple">
                 <Setter Property="Template">
                       <Setter.Value>
                             <ControlTemplate TargetType="{x:Type p:CellPresenter}">

                                   <Grid DataContext="{Binding Path=., RelativeSource={RelativeSource TemplatedParent}}" Margin="{Binding CellStyle.Margin}">
                                         <Border Margin="-4,0,0,0" Width="4" Background="Red" HorizontalAlignment="Left" />
                                         <Border BorderBrush="{Binding CellStyle.BorderBrush}" BorderThickness="{Binding CellStyle.BorderThickness}" Background="{Binding Background}" />
                                   </Grid>

                             </ControlTemplate>
                       </Setter.Value>
                 </Setter>
           </DataTrigger>

     </Style.Triggers>
</Style>[/code]
The above style is very similar to the default style of Timetable cells except that it adds a small red border to the left of the cell. We will use this style for the cells representing 'busy' time intervals.

Note that the namespace 'p' in the above XAML is defined as 'http://mindfusion.eu/scheduling/wpf'.

2. Handle the Calendar.CellPresenterCreated event and use an implementation similar to the following for the event handler:

[code]private void OnCellPresenterCreated(object sender, CellPresenterEventArgs e)
{
     // Perform a check if the cell is busy
     bool isBusy = false;
     if ((e.CellPresenter.Resource.Name == "Resource #1" ||
           e.CellPresenter.Resource.Name == "Resource #2") &&
           e.CellPresenter.StartTime.Hour > 12)
     {
           isBusy = true;
     }

     if (isBusy)
     {
           Style busyCellStyle = FindResource("BusyCellStyle") as Style;
           if (busyCellStyle != null)
                 e.CellPresenter.Style = busyCellStyle;
     }
}[/code]
The above code checks if the created CellPresenter corresponds to a busy cell and if so, associates our custom Style with it. The busy check in your case will be more complicated. In this sample we mark as busy all hours past 12:00 PM for the first two resources.

Let me know if this helps.

Regards,
Meppy
  
Back to top
 
IP Logged
 
yuri
YaBB Newbies
*
Offline



Posts: 3
Joined: May 12th, 2010
Re: Busy/Free/On sickleave,etc
Reply #2 - May 19th, 2010 at 11:13am
Print Post  
Got it Smiley
Works perfectly, thank you very much. I'm quite impressed by this control, most of all it is blazingly fast (as is your response Wink).
I'll be doing more tests in the coming days, so perhapse I'll have some more questions.
  
Back to top
 
IP Logged
 
yuri
YaBB Newbies
*
Offline



Posts: 3
Joined: May 12th, 2010
Re: Busy/Free/On sickleave,etc
Reply #3 - May 19th, 2010 at 12:19pm
Print Post  
Just wondering: did you create the above xaml with Expression Blend, or did you do this by hand from visual studio?
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Busy/Free/On sickleave,etc
Reply #4 - May 19th, 2010 at 12:38pm
Print Post  
This particular XAML is a manually modified copy of the default cell template.

Regards,
Meppy
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint