This is a migrated thread and some comments may be shown as answers.

Extending the Resource class

2 Answers 46 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Håkan
Top achievements
Rank 1
Håkan asked on 08 Sep 2011, 01:25 PM
Hi,

I need to extend the Resource class with some new properties that I need to display in the ResourceGroupHeader.

We use resources for employees in a scheduling tool.
We need to display how many minutes every employee is scheduled for and how many minutes he/she is allowed to work.

So I created a class called TimeScheduleEmployeeResource that looks like this:
public class TimeScheduleEmployeeResource : Resource
   {
       #region Extended properties
 
       private int plannedMinutes;
       public int PlannedMinutes
       {
           get { return plannedMinutes; }
           set { plannedMinutes = value; }
       }
 
       private int workingHoursMinutes;
       public int WorkingHoursMinutes
       {
           get { return workingHoursMinutes; }
           set { workingHoursMinutes = value; }
       }
 
       #endregion
   }

And my group header template looks like this:
<local:CustomOrientedGroupHeaderContentTemplateSelector.VerticalResourceTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center" Width="150">
                        <StackPanel.Resources>
                            <Style TargetType="TextBlock" BasedOn="{StaticResource DefaultTextBlock}">
                                <Setter Property="VerticalAlignment" Value="Center" />
                                <Setter Property="TextWrapping" Value="Wrap" />
                            </Style>
                        </StackPanel.Resources>
                        <TextBlock Text="{Binding Name}" Padding="5,3,5,0" />
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" Margin="5,0,5,3">
                            <TextBlock Text="{Binding PlannedMinutes, Converter={StaticResource MinutesToTimeSpanConverter}}" />
                            <TextBlock Text="/" />
                            <TextBlock Text="{Binding WorkingHoursMinutes, Converter={StaticResource MinutesToTimeSpanConverter}}" />
                        </StackPanel>
                    </StackPanel>
                </DataTemplate>
            </local:CustomOrientedGroupHeaderContentTemplateSelector.VerticalResourceTemplate>

But it will only display the employee name and the / no information from the two extended properties PlannedMinutes and WorkingHoursMinutes. My MinutesToTimeSpan converter is never called either.

I was puzzled by one thing. The first TextBlock is bound to the 'Name' property, but where is that defined?
The Resource class has a DisplayName property.

Am I overriding the wrong class here?

Regards,
Håkan





2 Answers, 1 is accepted

Sort by
0
Accepted
Rosi
Telerik team
answered on 12 Sep 2011, 07:00 AM
Hi Håkan,

The DataContext of the group header is not the Resource itself but an internal object. Actually the Name property represents the Resource and not the ResourceName property. To solve the issue I suggest you try changing your bindings like this:
<TextBlock Text="{Binding Name.PlannedMinutes, Converter={StaticResource MinutesToTimeSpanConverter}}" />

Regards,
Rosi
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Håkan
Top achievements
Rank 1
answered on 13 Sep 2011, 10:49 AM
Thanks!

That worked great.

Regards,
Håkan
Tags
ScheduleView
Asked by
Håkan
Top achievements
Rank 1
Answers by
Rosi
Telerik team
Håkan
Top achievements
Rank 1
Share this question
or