Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have the following control template;

XML
<ControlTemplate x:Key="NationalTweetLabel" TargetType="{x:Type Label}">
            <Grid Width="447" Height="129" RenderTransformOrigin="0.5,0.5">
                <Grid.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleX="1" ScaleY="1"/>
                        <SkewTransform AngleX="0" AngleY="0"/>
                        <RotateTransform Angle="0"/>
                        <TranslateTransform X="0" Y="0"/>
                    </TransformGroup>
                </Grid.RenderTransform>
                <Border Margin="0,0,0,31" VerticalAlignment="Stretch" Width="447" Height="97" Opacity="1" Background="#FF00FF18">
                    <TextBlock HorizontalAlignment="Left" VerticalAlignment="Top" Width="448" Height="72.5" Text="{Binding Message}" TextWrapping="Wrap"/>
                </Border>
                <TextBlock Name="Tweet" HorizontalAlignment="Right" Margin="0,0,45,8" VerticalAlignment="Bottom" Text="{Binding User}" TextWrapping="Wrap" d:LayoutOverrides="Height" RenderTransformOrigin="6.98,1.161"/>
                <Image HorizontalAlignment="Right" Margin="0,0,-9.5,-6" VerticalAlignment="Bottom" Width="51" Height="44" d:LayoutOverrides="Height" Source="bluebird.png"/>
                <Image Margin="0,0,0,31.5" Source="Images\top-message-layer.png"/>
            </Grid>
        </ControlTemplate>


The text property of the textblock "Tweet" is set to a binding source, which I want to be a string called User. I create a label in code and apply the template to it;

TextBlock textBlock = new TextBlock();
            textBlock.Template =(ControlTemplate)FindResource("NationalTweetLabel");


I don't know how to set the source of the binding for the Tweet textblock. I found code to get the element of the control template using textBlock.Template.FindName, but I don't know what to do with it after. Any help will be appreciated. Let me know if I haven't explained clearly enough.
Posted
Comments
[no name] 9-Mar-11 11:36am    
I am a little confused by what you are asking... You set the source for your binding already (in XAML). Now just add a public string property that is named "User".

What does getting the template have to do with this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900