Custom GanttTask with custom children's class

4 posts, 0 answers
  1. Kenny
    Kenny avatar
    16 posts
    Member since:
    Feb 2013

    Posted 19 Jun 2013 Link to this post

    Hello,
    In my project I'm using a custom collection which derrives from ObservableCollection, ex. CustomGanttCollection : ObservableCollection<CustomGanttTask>
    This gives me the possibility to add some extra methods...

    The same way as I declared my CustomGanttCollection
    , I declared my custom gantt task as: CustomGanttTask : GanttTask

    Now I thought using my CustomCollection as the Collection where the ChildTask are stored in by overriding the Children property of GanttTask in my CustomGantTask like:

    private <span style="font-size: 14px;">CustomGanttCollection _children</span><br>public <span style="font-size: 14px;">CustomGanttCollection Children<br></span>{<br><span class="Apple-tab-span" style="white-space:pre"> </span>get<br><span class="Apple-tab-span" style="white-space:pre"> </span>{<br><span class="Apple-tab-span" style="white-space:pre">       </span>return _children;<br><span class="Apple-tab-span" style="white-space:pre">   </span>}<br>}


    Offcourse I do add some tasks in my ViewModel to the children...

    Although this works (no compile errors, when I take a look at the Children property everything looks fine,...)  the GanttView Component won't show me the childtasks.

    Is there a way that I can use my custom collection as the children's collection? The GanttView must be able to use the collection as it already uses one for the top-level tasks...
  2. Kenny
    Kenny avatar
    16 posts
    Member since:
    Feb 2013

    Posted 19 Jun 2013 Link to this post

    Hello,
    In my project I'm using a custom collection which derrives from ObservableCollection, ex. CustomGanttCollection : ObservableCollection<CustomGanttTask>
    This gives me the possibility to add some extra methods...

    The same way as I declared my CustomGanttCollection
    , I declared my custom gantt task as: CustomGanttTask : GanttTask

    Now I thought using my CustomCollection as the Collection where the ChildTask are stored in by overriding the Children property of GanttTask in my CustomGantTask like:

    private CustomGanttCollection _children;
    public CustomGanttCollection Children
    {
    get
    {
    return _children;
    }
    }



    Offcourse I do add some tasks in my ViewModel to the children...

    Although this works (no compile errors, when I take a look at the Children property everything looks fine,...)  the GanttView Component won't show me the childtasks.

    Is there a way that I can use my custom collection as the children's collection? The GanttView must be able to use the collection as it already uses one for the top-level tasks...
  3. UI for WPF is Visual Studio 2017 Ready
  4. Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 19 Jun 2013 Link to this post

    Hello Kenny,

    From your sample code I can see that you have a property called Children which actually hides the Children property of the GanttTask, but the GanttView doesn't know about it and because of that it ignores it.

    There is no easy to implement alternative of your approach as the GanttTask class doesn't support its Children replaced to be changed - it creates its own in its constructor and it cannot be changed later.

    I can suggest you two different approaches which have their positives and negatives depending on your needs:
    1. If you need just to add functionality to your tasks collection (methods) and you don't need to add any data to it (properties and fields), I would suggest you to create some extension methods instead of inheriting the collection. This might also remove the need of inheriting the GanttTask class.
    2. As the GanttView also doesn't know about the GanttTask class, but only about the interfaces - IGanttTask, IMilestone, ISummary, IEditableHierarchical, IDependant, implemented by the GanttTask class, you could create your own implementation, which doesn't inherit from the GanttTask class.

    The second approach is more complicated, but allows you greater flexibility.

    Regards,
    Miroslav Nedyalkov
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  5. Kenny
    Kenny avatar
    16 posts
    Member since:
    Feb 2013

    Posted 21 Jun 2013 Link to this post

    Hello Miroslav,

    I solved it by doing a sync between my Children property and the base.Children property.

    In the constructor of my custom ganttask;

    _children = new MyCustomCollection(_project);
    _children.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(_children_CollectionChanged);

    And:

    void _children_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
    // Do a sync between _children (actually MyCustomCollection : ObservableCollection<CustomGanttTask>) and base.Children
    }

    This way I can use any collection I want, as long as I keep them synchronised...
Back to Top