Setting backcontent programmatically

Thread is closed for posting
2 posts, 0 answers
  1. Paul
    Paul avatar
    3 posts
    Member since:
    Apr 2012

    Posted 20 May 2012 Link to this post

    I'd like to set the text in a textblock in backcontent through code-behind. How do I do this? Here is my XAML:

    <telerikPrimitives:RadHubTile Message="" Height="171" Name="tileToday" Title="Tile Title" VerticalContentAlignment="Bottom" VerticalAlignment="Bottom"  Background="{StaticResource PhoneAccentBrush}" Width="171">
            <Border Background="{StaticResource PhoneAccentBrush}">
                <TextBlock Margin="6,6,6,6" TextWrapping="Wrap" HorizontalAlignment="Center"
        Text="** What I'd like to change **"/>
  2. Victor
    Victor avatar
    1358 posts

    Posted 21 May 2012 Link to this post

    Hello Paul,

    Thanks for the question.
    Since the back content of the hub tile is inside a data template, you will not have an auto-generated field if you set x:Name to your text block. In order to do it, you need to find the text block manually. Fortunately this case occurs a few times in our controls so we have a class that does just that. Assuming your hub tile is named hubTile and the text block in the back content named textBlock, to find the text block you have to do this:

    TextBlock textBlock = ElementTreeHelper.FindVisualDescendant<TextBlock>(this.hubTile, (child) => (child as FrameworkElement).Name == "textBlock");

    It is important to note that this code example will only work after the layout algorithm of the hub tile has passed because in Silverlight, DataTemplate objects are loaded during layout.

    Please write again if you need further assistance.

    Kind regards,
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top