Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I am trying to use the TimelinePanel control with a collection of item and I am having troubles making it work (nothing is showing). I am trying 2 different approach.

XAML:

HTML
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="1*" />
        <RowDefinition Height="1*" />
    </Grid.RowDefinitions>
    <Grid Grid.Row="0">
        <ItemsControl ItemsSource="{Binding list, Source={StaticResource viewModel}}">
            <ItemsControl.Template>
                <ControlTemplate TargetType="ItemsControl">
                    <xtc:TimelinePanel BeginDate="{Binding startHour, Source={StaticResource viewModel}}" EndDate="{Binding endHour, Source={StaticResource viewModel}}" Background="Aqua" />
                </ControlTemplate>
            </ItemsControl.Template>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Border Background="Blue" Width="100" Height="25" Margin="0, 2, 0, 2" xtc:TimelinePanel.Date="{Binding start}">
                        <TextBlock Text="{Binding name}" />
                    </Border>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Grid>
    <Grid Grid.Row="1">
        <xtc:TimelinePanel Background="LightBlue" BeginDate="{Binding startHour, Source={StaticResource viewModel}}" EndDate="{Binding endHour, Source={StaticResource viewModel}}">
            <ItemsControl ItemsSource="{Binding list, Source={StaticResource viewModel}}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Border Background="Blue" Width="100" Height="25" Margin="0, 2, 0, 2" xtc:TimelinePanel.Date="{Binding start}" xtc:TimelinePanel.DateEnd="{Binding end}">
                            <TextBlock Text="{Binding name}" />
                        </Border>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </xtc:TimelinePanel>
    </Grid>
</Grid>


and the code behind:

C#
public partial class MainWindow : Window

    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }
 
    public class timeViewModel
    {
        public DateTime startHour
        {
            get; set;
        }
 
        public DateTime endHour
        {
            get; set;
        }
 
        public ObservableCollection&lt;timelineItem&gt; list { get; set; }
 
        public timeViewModel()
        {
            startHour = DateTime.Now.Date;
            endHour = (DateTime.Now.Date + TimeSpan.FromDays(22));
            getData();
        }
 
        private void getData()
        {
            List&lt;timelineItem&gt; listItem = new List&lt;timelineItem&gt;();
            for (int i = 6; i &lt; 20; i++)
            {
                timelineItem newItem = new timelineItem();
                newItem.name = &quot;test &quot; + i.ToString();
                newItem.start = (DateTime.Now.Date + TimeSpan.FromDays(i));
                newItem.end = (DateTime.Now.Date + TimeSpan.FromDays(i + 2));
                listItem.Add(newItem);
            }
            list = new ObservableCollection&lt;timelineItem&gt;(listItem);
        }
    }
}
 
public class timelineItem
{
    public string name { get; set; }
    public DateTime start { get; set; }
    public DateTime end { get; set; }
}


Any help on how the show the item on the timelinepanel would be great.

Thanks

Pierre
Posted
Updated 29-Nov-15 9:58am
v2

1 solution

Received solution from Xceed:
Hi,

I would not use "ItemsControl.Template" and "ItemsControl.ItemTemplate", but instead use :
-"ItemsControl.ItemsPanel" to define the panel to use : TimelinePanel,
-"ItemsControl.ItemTemplate" to define the visual of each item,
-"ItemsControl.ItemContainerStyle" to define the attached property "Date" and "DateEnd". This is necessary since the ItemsControls will automatically create ContentPresenter for each items with the content being the "Border" defined in ItemsControl.ItemTemplate. To work correctly, the TimelinePanel needs to find the attached property "Date" and "DateEnd" at top level on its items, so on the ContentPresenters.

Something like :

XML
<grid>
        <itemscontrol x:name="_itemsControl" xmlns:x="#unknown">
                      ItemsSource="{Binding list, Source={StaticResource viewModel}}">
            <itemscontrol.itemspanel>
              <itemspaneltemplate>
                  <xtc:timelinepanel begindate="{Binding startHour, Source={StaticResource viewModel}}" xmlns:xtc="#unknown">
                                    EndDate="{Binding endHour, Source={StaticResource viewModel}}"
                                    Background="Aqua"/>
              </xtc:timelinepanel></itemspaneltemplate>
            </itemscontrol.itemspanel>
            <itemscontrol.itemtemplate>
              <datatemplate>
                  <border background="Blue">
                          Height="25"
                          Margin="0, 2, 0, 2">
                    <textblock text="{Binding name}">
                                Foreground="White"/>
                  </textblock></border>
              </datatemplate>
            </itemscontrol.itemtemplate>
            <itemscontrol.itemcontainerstyle>
              <style>
                  <setter property="xtc:TimelinePanel.Date">
                          Value="{Binding Path=start}"/>
                  <setter property="xtc:TimelinePanel.DateEnd">
                          Value="{Binding Path=end}" />
              </setter></setter></style>
            </itemscontrol.itemcontainerstyle>
        </itemscontrol>
      </grid>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900