Silverlight for Windows Phone supports three basic types of bindings categorized
based on the source of the data.
The third type of binding is
called RelativeSource. In the Windows
Presentation Foundation, RelativeSource is much more flexible than the version in
Silverlight, so you may not be very impressed with this option. One of
the purposes of RelativeSource is in connection with templates. The only other option allows you to
define a binding that references a property of the same element, known
as Self. The
following program shows the syntax:
Example 1. Silverlight
Project: BindToSelf File: MainPage.xaml (excerpt)
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="{Binding RelativeSource={RelativeSource Self}, Path=FontFamily}" />
<TextBlock Text=" - " />
<TextBlock Text="{Binding RelativeSource={RelativeSource Self}, Path=FontSize}" />
<TextBlock Text=" pixels" /> </StackPanel> </Grid>
|
The property RelativeSource
is set to another markup extension containing RelativeSource
and Self. The Path then refers
to another property of the same element. Thus, the TextBlock
elements display the FontFamily and FontSize of the TextBlock.