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

How to Bind Dictionary to RadTimeline

3 Answers 37 Views
TimeLine
This is a migrated thread and some comments may be shown as answers.
Manuel
Top achievements
Rank 1
Manuel asked on 08 Sep 2015, 09:04 PM

Hi, 

 

How can I bind a Dictionary object to a Timeline.

 

For example:

 MyMainClass with the Attribute Dictionary

    Dictionary <string,MycustomObject> myObject = new Dictionary <string,MycustomObject>();

 

MycustomObject

Dictionary<int,AnotherObject> myOtherDictionary = new Dictionary<int,ANotherObject> ();

Date StartDate

Date EndDate

 

Class AnotherObject

 

Date DateItem

int DurationItem

 

I tried to asign to the ItemSource the dictionary in this way  but it doesn't work 

 

ItemSource="{Binding Path=myObject}"

StartDate="{Binding StartDate}"

DurationPath=DurationItem

Thanx's in advance

3 Answers, 1 is accepted

Sort by
0
Peshito
Telerik team
answered on 11 Sep 2015, 10:30 AM
Hello Manuel,

You can data bind the Timeline with a Dictionary by using its Key and Value parameters. For instance:
<telerik:RadTimeline Height="250"
               VerticalAlignment="Top"
               Margin="6"
               PeriodStart="{Binding StartDate, Mode=TwoWay}"
               PeriodEnd="{Binding EndDate, Mode=TwoWay}"
               StartPath="Value"
               DurationPath="Key"
               ItemsSource="{Binding Data}">
       <telerik:RadTimeline.Intervals>
           <telerik:YearInterval />
           <telerik:MonthInterval />
           <telerik:WeekInterval />
           <telerik:DayInterval />
       </telerik:RadTimeline.Intervals>
   </telerik:RadTimeline>
Attached is a sample project demonstrating this approach.

Hope it helps.

Regards,
Peshito
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Manuel
Top achievements
Rank 1
answered on 12 Sep 2015, 07:15 PM

Hi Peshito



Thank you for your answer. It works.

 But what if the object that is assigned to the datacontext is not an "object" but a Dictionary.

 
I mean in the example that you attach  is posible not to assign the product object  but  assign a Dictionary to the context  like

 

Dictionary<string, Product> myDictionary = new Dictionary<string, Product>();

myDictionary.Add("1",new Product () { StartDate=dateStart,EndDate:endDate,Data=items});

myDictionary.Add("2",new Product () { StartDate=dateStart,EndDate:endDate,Data=items});

 (obviously Keeping the structure of product object )

Is this possible ?


0
Peshito
Telerik team
answered on 16 Sep 2015, 08:56 AM
Hello Manuel,

If I understood you correctly what you would like to achieve is to set a different datacontext depending on the key value of your Dictionary. If this is so, changing the MainWindow() constructor like shown below should do the job:
public MainWindow()
{
    InitializeComponent();
     
    var startDate = DateTime.Today;
    var endDate = DateTime.Today.AddYears(1);
 
 
    var items = new Dictionary<TimeSpan, DateTime>();
    for (int i = 1; i <= 10; i++)
    {
        items.Add(TimeSpan.FromDays(10 + i * 5), DateTime.Today.AddMonths(i));
    }
 
    //this.DataContext = new Product() { StartDate = startDate, EndDate = endDate, Data = items };
 
    Dictionary<string, Product> myDictionary = new Dictionary<string, Product>();
 
    myDictionary.Add("1", new Product() { StartDate = startDate, EndDate = endDate, Data = items });
 
    myDictionary.Add("2", new Product() { StartDate = startDate, EndDate = endDate, Data = items });
 
    this.timeline.DataContext = myDictionary["1"];
}
In case this is not what you meant, please keep in mind that the Timeline control works with a single collection from your ViewModel and you should keep all the data that you want to display in the Timeline in one place.

Regards,
Peshito
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
TimeLine
Asked by
Manuel
Top achievements
Rank 1
Answers by
Peshito
Telerik team
Manuel
Top achievements
Rank 1
Share this question
or