I have senario where I require to have multiple shapes and each shape will be having different dataTemplate.
For example: In one shape i will be having the Textblock and a checkbox, in another shpae i will be having Textblock with an image.
Do you have any exmaple where i can have a look at it.
Thanks in advance.
3 Answers, 1 is accepted
For this scenario, the diagram exposes a ShapeTemplateSelector property, which represents a DataTemplateSelector. When inherited, you can override the SelectTemplate method which selects a specific DataTemplate for a particular item and container.
Kind regards,Alex Fidanov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
I have followed the same method but was not ablw to achive it.
ChildWindow
<
locall:TaskListDataTemplateSelector x:Key="myDataTemplateSelector">
</locall:TaskListDataTemplateSelector>
<DataTemplate x:Key="LoanTemplate" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Text}" Grid.Row="0" Grid.Column="0" />
<Image Width="60" Height="30" Source="component/Test/1.png"
Grid.Row="0" Grid.Column="1"/>
</Grid>
</DataTemplate>
<Style x:Key="BusinessTemplate" TargetType="telerik:RadDiagramShape">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Text}" GotFocus="Image_GotFocus" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Grid.RowSpan="2" />
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
<
telerik:RadDiagram x:Name="diagram" MinWidth="500" Margin="-1 -1 0 0"
ConnectionStyle="{StaticResource ConnectionStyle}"
IsBackgroundSurfaceVisible="{Binding IsGridVisible, Mode=TwoWay}"
IsSnapToGridEnabled="{Binding IsSnapEnabled, Mode=TwoWay}"
primitives:GraphPaper.CellSize="{Binding CellSize}"
primitives:GraphPaper.LineStroke="{Binding SelectedColor, ElementName=GridColorEditor, Converter={StaticResource colorToBrushConverter}}"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollBarVisibility="Hidden" SnapX="{Binding SnapX, Mode=TwoWay}"
SnapY="{Binding SnapY, Mode=TwoWay}" Zoom="{Binding ZoomLevel, Mode=TwoWay}"
ShapeEditTemplateSelector="{StaticResource myDataTemplateSelector}" >
</telerik:RadDiagram>
C#
public class TaskListDataTemplateSelector : DataTemplateSelector
{
DataTemplate LoanTemplate;
DataTemplate BusinessTemplate;
public TaskListDataTemplateSelector()
{ }
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
FrameworkElement page = Application.Current.RootVisual as FrameworkElement;
LoanTemplate = page.Resources[
"LoanTemplate"] as DataTemplate;
BusinessTemplate = page.Resources[
"BusinessTemplate"] as DataTemplate;
if (item.GetType() == typeof(test))
{
test t = new test();
t = (
test)item;
if (t.type == //shapetype)
{
return LoanTemplate;
}
else
{
return BusinessTemplate;
}
}
return null;
}
}
Thanks Alex.