Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - How do I get to a TextBlock inside a Style

 
 
Old 03-27-2007   #1 (permalink)
Bruce Parker


 
 

How do I get to a TextBlock inside a Style

I have defined the following style:

<Style x:Key="EmployeeRequestCustomHeaderLabelArea" TargetType="{x:Type
igDP:HeaderLabelArea}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:HeaderLabelArea}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock TextAlignment="Center" Grid.Row="0" FontSize="16"
FontStyle="Oblique" Foreground="White" Text="Are Awaiting Your
Approval"></TextBlock>
<ContentPresenter Grid.Row="1" Content="{TemplateBinding
Content}"/>
</Grid>
</ControlTemplate>

</Setter.Value>
</Setter>
</Style>

The style is used here:

<igDP:XamDataPresenter x:Name="EmployeeRequestDataPresenter">
<igDP:XamDataPresenter.FieldLayoutSettings>

<igDP:FieldLayoutSettings
HeaderrLabelAreaStyle="{StaticResource

EmployeeRequestCustomHeaderLabelArea}"/>
</igDP:XamDataPresenter.FieldLayoutSettings>


How can I programmatically change the Text property in the TextBlock?



My System SpecsSystem Spec
Old 03-27-2007   #2 (permalink)
Laurent Bugnion [MVP]


 
 

Re: How do I get to a TextBlock inside a Style

Hi,

Bruce Parker wrote:
> I have defined the following style:
>
> <Style x:Key="EmployeeRequestCustomHeaderLabelArea" TargetType="{x:Type
> igDP:HeaderLabelArea}">
> <Setter Property="Template">
> <Setter.Value>
> <ControlTemplate TargetType="{x:Type igDP:HeaderLabelArea}">
> <Grid>
> <Grid.RowDefinitions>
> <RowDefinition />
> <RowDefinition />
> </Grid.RowDefinitions>
> <TextBlock TextAlignment="Center" Grid.Row="0" FontSize="16"
> FontStyle="Oblique" Foreground="White" Text="Are Awaiting Your
> Approval"></TextBlock>
> <ContentPresenter Grid.Row="1" Content="{TemplateBinding
> Content}"/>
> </Grid>
> </ControlTemplate>
>
> </Setter.Value>
> </Setter>
> </Style>
>
> The style is used here:
>
> <igDP:XamDataPresenter x:Name="EmployeeRequestDataPresenter">
> <igDP:XamDataPresenter.FieldLayoutSettings>
>
> <igDP:FieldLayoutSettings
> HeaderrLabelAreaStyle="{StaticResource
>
> EmployeeRequestCustomHeaderLabelArea}"/>
> </igDP:XamDataPresenter.FieldLayoutSettings>
>
>
> How can I programmatically change the Text property in the TextBlock?


I'd say the easiest way is to set a Name on the TextBlock. Then you can use:

TextBlock myText
= bn.Template.FindName( "myTextBlock", bn ) as TextBlock;
if ( myText != null )
{
myText.Text = "World";
}

Note: The VisualTree is not expanded yet in the Window's constructor, so
you have to wait until the Loaded event is fired to access the
Template's elements.

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Font Size - XP style vs Vista style Vista General
Font Size - XP style vs Vista style Vista General
Font Size - XP style vs Vista style Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46