Hello Everybody,
I have faced with the following situation which I cannot resolve myself,
I need to set an Icon in the legend item, and have created the following LegentItem Style.
<Style x:Key="LegendItemIconStyle" TargetType="ig:LegendItem">
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ig:LegendItem">
<StackPanel Orientation="Horizontal" Margin="0,0,0,0">
<Image Width="12" Height="12" Margin="12,2,12,6"
Source="{Binding Path=BitmapSource, Mode=TwoWay}" />
<ig:Title Content="{TemplateBinding Content}" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
But I have no idea how I can get access to the DataContext of the LegendItem. On DateTimeSerie I cannot get access to it. So probably I am doing this wrong and there is a better way of doing that. So basically the request is to show an icon and to bind it to the Source Property somehow.
Any help would be very appreciated,
Reagards,
Kirill
Hi,
You can specify the Legend Item per series style with Series.LegendItemStyle property. You can modify the following code:
<ig:XamTimeline>
<ig:XamTimeline.Series>
<ig:NumericTimeSeries Title="Series 1">
<ig:NumericTimeSeries.LegendItemStyle>
<Style TargetType="ig:LegendItem">
<StackPanel Orientation="Horizontal">
<!--<Image Source="imageSource" /> static image source -->
<Ellipse Width="8"
Height="8"
Fill="{TemplateBinding Fill}"
Stroke="{TemplateBinding Stroke}"
StrokeThickness="1" />
<ig:Title Content="{TemplateBinding Content}"
Margin="5,0,0,0"
Foreground="{TemplateBinding Foreground}" />
</ig:NumericTimeSeries.LegendItemStyle>
</ig:NumericTimeSeries>
</ig:XamTimeline.Series>
</ig:XamTimeline>
Hello!
Thanks for the reply but probably we dindt get each other. The problem with usage of datacontext for that template.
How can I bind datacontext for the LegendItem. Because if I set datacontext for the series, it is not available than for legendItem.
Or other way of asking - how cai I have legendIitem with custom icon. And that Icon is not predefined by default and will be defined only in runtime.
Thanks!
I’m sending you a sample that defines the legend icon as image, which image source is created at runtime.
Is there any way to use a DataContext for the LegenfItem?
Or to use an icon in the legentItem but the icon defines on runtime?
Hi Teodor,
Thanks for the answer.
I would do that if I could, but that DataContext is not predefined and only will be available on runtime.
Looks like there is no way to implement a custom icon for the legentItem.
Unfortunately, the legend item doesn’t get the series data context, but you can define the data context in the legend item style. Try using this code:
<StackPanel.DataContext>
<local:SeriesContext />
</StackPanel.DataContext>
<Image Width="12"
Height="12"
Margin="12,2,12,6"
Source="{Binding BitmapSource}" />