Extending the Resource class

3 posts, 1 answers
  1. Håkan
    Håkan avatar
    183 posts
    Member since:
    May 2011

    Posted 08 Sep 2011 Link to this post


    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; }

    And my group header template looks like this:
                        <StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center" Width="150">
                                <Style TargetType="TextBlock" BasedOn="{StaticResource DefaultTextBlock}">
                                    <Setter Property="VerticalAlignment" Value="Center" />
                                    <Setter Property="TextWrapping" Value="Wrap" />
                            <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}}" />

    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?


  2. Answer
    Rosi avatar
    2529 posts

    Posted 12 Sep 2011 Link to this post

    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}}" />

    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 >>

  3. Håkan
    Håkan avatar
    183 posts
    Member since:
    May 2011

    Posted 13 Sep 2011 Link to this post


    That worked great.

Back to Top