ContentTemplate example

4 posts, 0 answers
  1. Russell Mason
    Russell Mason avatar
    87 posts
    Member since:
    Oct 2006

    Posted 14 Dec 2009 Link to this post

    Hi

    Do you have an example of how to set the ContentTemplate of a RadWindow? I want to have information above and below the actual Content as set by the property but when I set the ContentTemplate the actual Content disappears. I'm obviously doing something wrong.

    Thanks
    Russell Mason
  2. Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 15 Dec 2009 Link to this post

    Hi Russell,

     Here is an example of a ContentTemplate of the RadWindow control:

    <DataTemplate>
        <Grid Background="White">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
             
            <TextBlock Text="Some Header" Grid.Row="0" />
            <ContentPresenter Grid.Row="1" Content="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}" />
            <TextBlock Text="Some Footer" Grid.Row="2" />
        </Grid>
    </DataTemplate>


    All the best,
    Miroslav Nedyalkov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
  4. Derek
    Derek avatar
    2 posts
    Member since:
    Oct 2013

    Posted 17 Oct 2013 Link to this post

    HI,
    This is my first post so please forgive me if I do not provide enough information!  I would like to do the same thing as shown below but with the added complication of binding data.

    Example ({Binding HeaderText}):
    <DataTemplate>
    <Grid Background="White">
    <Grid.RowDefinitions>
    <RowDefinition />
    <RowDefinition />
    <RowDefinition />
    </Grid.RowDefinitions>
    <TextBlock Text="{Binding HeaderText}" Grid.Row="0" />
    <ContentPresenter Grid.Row="1" Content="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}" />
    <TextBlock Text="Some Footer" Grid.Row="2" />
    </Grid>
    </DataTemplate>

    How is this accomplished?  My requirements are actually for a list of mulitple items as shown below:

     

    <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" MaxHeight="100" MinHeight="100" MinWidth="100">
        <ItemsControl ItemsSource="{Binding NonInstructAccounts}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding [AccountNumber].TextValue}" />
                        <TextBlock Text="{Binding [AccountNameLine1].TextValue}" Margin="10,0,0,0" />
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </ScrollViewer>

  5. Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 21 Oct 2013 Link to this post

    Hi Derek,

    In order to display a collection of Items you would need to set the ContentTemplate of the ContentPresenter the desired way. It should look like follows:
    ...
    <ContentPresenter Grid.Row="1" Content="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}">
        <ContentPresenter.ContentTemplate>
            <DataTemplate>
                <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" MaxHeight="100" MinHeight="100" MinWidth="100">
                    <ItemsControl ItemsSource="{Binding NonInstructAccounts}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding [AccountNumber].TextValue}" />
                                    <TextBlock Text="{Binding [AccountNameLine1].TextValue}" Margin="10,0,0,0" />
                                </StackPanel>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </ScrollViewer>
            </DataTemplate>
        </ContentPresenter.ContentTemplate>
    </ContentPresenter>
    ...

    Hope this helps. If you have any other questions let us know.

    Regards,
    Kalin
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top