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

Multiple controlTemplate Support

3 Answers 91 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Muralee
Top achievements
Rank 1
Muralee asked on 19 Jun 2012, 02:30 PM
Hi,

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

Sort by
0
Accepted
Alex Fidanov
Telerik team
answered on 19 Jun 2012, 03:16 PM
Hi,

 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 >>

0
Muralee
Top achievements
Rank 1
answered on 19 Jun 2012, 03:35 PM
Thank you for the Quick response.

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;

 

}

}

0
Muralee
Top achievements
Rank 1
answered on 19 Jun 2012, 06:20 PM
My Bad. I have selected the wrong tag.

Thanks Alex.
Tags
Diagram
Asked by
Muralee
Top achievements
Rank 1
Answers by
Alex Fidanov
Telerik team
Muralee
Top achievements
Rank 1
Share this question
or