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

Combining TimelineContainerSelector

4 Answers 91 Views
GanttView
This is a migrated thread and some comments may be shown as answers.
Kourosh
Top achievements
Rank 1
Kourosh asked on 29 May 2018, 07:16 AM

Hi Progress,

 

I was wondering if it is possible to combine BaseLine_WPF project and ProjectDeadline_WPF project inside your xaml-sdk-master samples/Examples?

If I have understood this correctly, TimelineContainerSelector in Xaml can only have one child. How can I give several behaviors to TimelineContainerSelector?

 

Thanx

Best Regards

kourosh

4 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 31 May 2018, 12:58 PM
Hello Kourosh,

You can have only a single timeline container selector, but you can return different container types based on a condition. For example:
public class TimeLineCustomContainerSelector : DefaultTimeLineContainerSelector
{
    protected static readonly ContainerTypeIdentifier BaselineContainerType = ContainerTypeIdentifier.FromType<BaselineContainer>();
    private static readonly ContainerTypeIdentifier DeadlineEventInfoContainerType = ContainerTypeIdentifier.FromType<TimeLineDeadlineContainer>();
 
    public override ContainerTypeIdentifier GetContainerType(object item)
    {
        if (item is BaselineEventInfo)
        {
            return BaselineContainerType;
        }
        else if (item is TimeLineDeadlineEventInfo)
        {
            return DeadlineEventInfoContainerType;
        }
        return base.GetContainerType(item);
    }
}
I hope that helps.

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Kourosh
Top achievements
Rank 1
answered on 02 Jun 2018, 04:15 AM

Hi Martin,

Thank you for your reply.

It seems to me that there are parts missing!

What about the behavior? How should TimeLineBaselineBehavior look like? I mean the behavior part is also different in projectdeadline and baseline samples:

<telerik:RadGanttView x:Name="GanttView"
                              TasksSource="{Binding Tasks}"
                              SelectedItem="{Binding SelectedTask, Mode=TwoWay}"
                              InitialExpandBehavior="Expanded"
                              Grid.Row="1"
                              VisibleRange="{Binding VisibleRange}"
                              TimeLineVisualizationBehavior="{Binding TimeLineBaselineBehavior}"
                              PixelLength="{Binding PixelLenght, Mode=TwoWay}"
                              >

Could you give me a whole working sample that shows how I can put ProjectDeadline sample  and BaseLine sample in your sample package together? It would help a lot.

Best Regards

Kourosh

0
Kourosh
Top achievements
Rank 1
answered on 02 Jun 2018, 04:43 AM

Hi Martin,

I got it! In case someone else needs it.

I put 2 behaviors together in a new file called TimeLineCustomBehavior like this:

 

public class TimeLineCustomBehavior : DefaultGanttTimeLineVisualizationBehavior
    {
        private DateTime projectDeadline;

        public DateTime ProjectDeadline
        {
            get { return this.projectDeadline; }
            set
            {
                if (this.projectDeadline != value)
                {
                    this.projectDeadline = value;
                    this.OnPropertyChanged(string.Empty);
                }
            }
        }

        protected override IEnumerable GetBackgroundData(TimeLineVisualizationState state)
        {
            foreach (var background in base.GetBackgroundData(state))
            {
                yield return background;
            }

            var visibleRange = state.VisibleTimeRange;
            var deadline = state.Rounder.Round(new DateRange(this.projectDeadline, this.projectDeadline));
            var deadlineRange = new Range<long>(deadline.Start.Ticks, deadline.End.Ticks);

            if (visibleRange.IntersectsWith(deadlineRange))
            {
                yield return new TimeLineDeadlineEventInfo(deadlineRange);
            }
        }

        protected override IEnumerable<IEventInfo> GetEventInfos(TimeLineVisualizationState state, HierarchicalItem hierarchicalItem)
        {
            foreach (var eventInfo in base.GetEventInfos(state, hierarchicalItem))
            {
                yield return eventInfo;
            }

            var task = hierarchicalItem.SourceItem as CustomGanttTask;
            var baselineStartDate = task != null ? task.StartPlannedDate : DateTime.MinValue;

            if (baselineStartDate != null && baselineStartDate != DateTime.MinValue)
            {
                var roundedDeadline = state.Rounder.Round(new DateRange(baselineStartDate, task.EndPlannedDate));
                var baselineRange = new Range<long>(roundedDeadline.Start.Ticks, roundedDeadline.End.Ticks);

                if (baselineRange.IntersectsWith(state.VisibleTimeRange))
                {
                    yield return new BaselineEventInfo(baselineRange, hierarchicalItem.Index, hierarchicalItem.SourceItem as CustomGanttTask);
                }
            }
        }
    }

 

and then in ViewModel initiated it:

private ITimeLineVisualizationBehavior timeLineCustomBehavior;

public ITimeLineVisualizationBehavior TimeLineCustomBehavior
        {
            get
            {
                return timeLineCustomBehavior;
            }
            set
            {
                timeLineCustomBehavior = value;
                OnPropertyChanged(() => this.timeLineCustomBehavior);
            }
        }

inside the constructor:

this.timeLineCustomBehavior = new TimeLineCustomBehavior();

and in Example.xaml:

<telerik:RadGanttView x:Name="GanttView"
                              TasksSource="{Binding Tasks}"
                              SelectedItem="{Binding SelectedTask, Mode=TwoWay}"
                              InitialExpandBehavior="Expanded"
                              Grid.Row="1"
                              VisibleRange="{Binding VisibleRange}"
                              TimeLineVisualizationBehavior="{Binding TimeLineCustomBehavior}"
                              PixelLength="{Binding PixelLenght, Mode=TwoWay}"
        >

 

It works!

Please do comment Martin.

 

Best Regards

Kourosh

0
Martin Ivanov
Telerik team
answered on 04 Jun 2018, 08:20 AM
Hello Kourosh,

I am glad that you found a solution. And thank you for sharing it here.

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GanttView
Asked by
Kourosh
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Kourosh
Top achievements
Rank 1
Share this question
or