I have been using XamTimLine control for a while.Is there any way to trigger click event when the user clicks "Event Title"?.I have tried with MouseLeftButtonDown event but it is not getting triggered.Pls have a look at the code i have tried. I have also attached the sample snapshot for understanding.
<igtl:XamTimeline.Series> <igtl:DateTimeSeries Title="Input Events" Fill="Red" Position="TopOrLeft" MouseLeftButtonDown="Clicked"> <igtl:DateTimeSeries.Entries> <igtl:DateTimeEntry Time="00:00:01" Title="Event 1" Details="Details Time Entry 1" MouseLeftButtonDown="Clicked" ToolTip = "One"/> <igtl:DateTimeEntry Time="00:00:01" Title="Event 2" Details="Details Time Entry 1" MouseLeftButtonDown="Clicked" ToolTip = "Two"/> <igtl:DateTimeEntry Time="00:00:01" Title="Event 3" Details="Details Time Entry 1" MouseLeftButtonDown="Clicked" ToolTip = "Three"/> <igtl:DateTimeEntry Time="00:00:01" Title="Event 4" Details="Details Time Entry 1" MouseLeftButtonDown="Clicked" ToolTip = "Four"/> </igtl:DateTimeSeries.Entries> </igtl:DateTimeSeries></igtl:XamTimeline.Series>
And then add the style to the series. <ig:XamTimeline.Series> <ig:NumericTimeSeries Title="Default Title Style" Fill="White" EventTitleStyle="{StaticResource eventTitleStyle}"
How would I do this dynamically in code? I am dynamically building time series, so I can't staticly define series in XAML. I tried the code fragments below, but it does not work and infact, I changed the style of the original example to be a single textbox, and don't see the style of the display change, so I suspect it is not even using the eventTitleStyle:
<Window.Resources>
...
<ControlTemplate TargetType="ig:EventTitle" >
<Border HorizontalAlignment="Left" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}">
<TextBlock Text="{TemplateBinding Title}" TextWrapping="Wrap" Grid.Row="1" MouseLeftButtonDown="EventItemGrid_MouseLeftButtonDown"/>
</Border>
</ControlTemplate>
Here is the dynamic creation of time series:
if (displayedConstraintEntries.Count > 0)
{
DateTimeSeries constraintSeries = new DateTimeSeries()
EventDetailsStyle = this.Resources["eventTitleStyle"] as Style,
Title = "Constraint Period",
DataSource = displayedConstraintEntries,
DataMapping = "Time=Time;Duration=Duration;Title=Title;Details=Details",
Position = Position.BottomOrRight
};
m_xamTimeline.Series.Add(constraintSeries);
}
Thanks for ur quick reply..It is working fine:)
Hi,
You could re-templated the EventTitle style and add the MouseLeftButtonDown to the Grid in the template.
<Style x:Key="eventTitleStyle" TargetType="ig:EventTitle" >
<Setter Property="MaxWidth" Value="180" />
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Background" Value="White" />
<Setter Property="Foreground" Value="#FF333333"/>
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="PointStringFormat" Value="{}[{0}]" />
<Setter Property="SpanStringFormat" Value="{}[{0}-{1}]" />
<Setter Property="LineStyle">
<Setter.Value>
<Style TargetType="Line">
<Setter Property="StrokeThickness" Value="1" />
<Setter Property="Stroke" Value="Black" />
<Setter Property="Canvas.ZIndex" Value="-1" />
</Style>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Border HorizontalAlignment="Left"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}">
<Grid Background="{x:Null}" MouseLeftButtonDown="EventItemGrid_MouseLeftButtonDown">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="{TemplateBinding FormattedText}" TextWrapping="Wrap" />
<TextBlock Text="{TemplateBinding Title}" TextWrapping="Wrap" Grid.Row="1"/>
</Grid>
And then add the style to the series.
<ig:XamTimeline.Series>
<ig:NumericTimeSeries Title="Default Title Style" Fill="White"
EventTitleStyle="{StaticResource eventTitleStyle}"
and of course handle the code behind.
private void EventItemGrid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
Grid g = sender as Grid;
DependencyObject dp = VisualTreeHelper.GetParent(g);
while (dp != null && dp.GetType() != typeof(EventTitle))
dp = VisualTreeHelper.GetParent(dp);
if (dp.GetType() == typeof(EventTitle))
EventTitle et = dp as EventTitle;
NumericTimeEntry nte = et.EventEntry as NumericTimeEntry;
(this.xamTimeline0.Axis as NumericTimeAxis).SelectedTime = nte.Time;
Let me know if you have any questions.