Multiple controlTemplate Support

4 posts, 1 answers
  1. Muralee
    Muralee avatar
    7 posts
    Member since:
    Jun 2012

    Posted 19 Jun 2012 Link to this post

    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.
  2. Answer
    Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 19 Jun 2012 Link to this post

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

  3. DevCraft banner
  4. Muralee
    Muralee avatar
    7 posts
    Member since:
    Jun 2012

    Posted 19 Jun 2012 Link to this post

    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;

     

    }

    }

  5. Muralee
    Muralee avatar
    7 posts
    Member since:
    Jun 2012

    Posted 19 Jun 2012 Link to this post

    My Bad. I have selected the wrong tag.

    Thanks Alex.
Back to Top