<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rodrigo Díaz Concha &#187; RelativeSource</title>
	<atom:link href="http://rdiazconcha.com/tag/relativesource/feed/" rel="self" type="application/rss+xml" />
	<link>http://rdiazconcha.com</link>
	<description>Silverlight y XAML en Español para México, Latinoamérica y España</description>
	<lastBuildDate>Thu, 02 Feb 2012 20:54:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Silverlight 3 Beta 1: Enlace con RelativeSource</title>
		<link>http://rdiazconcha.com/2009/05/silverlight-3-beta-1-enlace-relativesource/</link>
		<comments>http://rdiazconcha.com/2009/05/silverlight-3-beta-1-enlace-relativesource/#comments</comments>
		<pubDate>Fri, 15 May 2009 20:02:04 +0000</pubDate>
		<dc:creator>Rodrigo</dc:creator>
				<category><![CDATA[Silverlight 3]]></category>
		<category><![CDATA[RelativeSource]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://rdiazconcha.com/?p=216</guid>
		<description><![CDATA[Silverlight 3 Beta 1: Enlace con RelativeSource
Hace algunos días escribí acerca del Enlace entre Elementos, una de las nuevas características presentes en Silverlight 3 Beta 1 (tomadas de su hermano mayor WPF).  Para complementar ese artículo he decidido hablar por separado de RelativeSource: una propiedad que podemos encontrar en el markup extension Binding.  Esta propiedad [...]]]></description>
			<content:encoded><![CDATA[<h1>Silverlight 3 Beta 1: Enlace con RelativeSource</h1>
<p>Hace algunos días escribí acerca del <a href="http://rdiazconcha.com/?p=185">Enlace entre Elementos</a>, una de las nuevas características presentes en Silverlight 3 Beta 1 (tomadas de su hermano mayor WPF).  Para complementar ese artículo he decidido hablar por separado de RelativeSource: una propiedad que podemos encontrar en el markup extension Binding.  Esta propiedad en Silverlight soporta dos valores tal y como se describen a continuación:</p>
<h2>Self</h2>
<p>Cuando establecemos un Binding con RelativeSource=Self estamos indicando que el origen del enlace es el mismo elemento en donde lo estamos estableciendo.  El siguiente fragmento de código explica mejor este concepto:</p>
<div id="codeSnippetWrapper" style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; max-height: 200px; font-size: 8pt; cursor: text;">
<div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">Slider</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="slider"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="250"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="20"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="100"</span> <span style="color: #ff0000;">Minimum</span><span style="color: #0000ff;">="0"</span> <span style="color: #ff0000;">Maximum</span><span style="color: #0000ff;">="250"</span> <span style="color: #0000ff;">/&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;">            <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">Ellipse</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="elipse"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="{Binding ElementName=slider, Path=Value}"</span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;">                     <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="{Binding Path=Width, RelativeSource={RelativeSource Self}}"</span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;">                     <span style="color: #ff0000;">Fill</span><span style="color: #0000ff;">="Purple"</span> <span style="color: #0000ff;">/&gt;</span></pre>
<p><!--CRLF--></div>
</div>
<p>En este ejemplo tenemos una Ellipse un Slider.  La propiedad Width de la Ellipse está enlazada con la propiedad Value del Slider, justo como lo vimos <a href="http://rdiazconcha.com/?p=185">en este artículo</a>.  Aquí el punto interesante es ver cómo la propiedad Height está enlazada a la propiedad Width de el elemento mismo.  Esto es logrado estableciendo la propiedad RelativeSource a Self, a través del markup extension {RelativeSource}.</p>
<h2>TemplatedParent</h2>
<p>El otro valor que podemos establecer en RelativeSource es TemplatedParent.  Esta opción indica que el valor lo tomará del control en donde estemos aplicando la plantilla en cuestión, por lo tanto esta opción solo es válida dentro de la declaración de una Platilla.  El siguiente código muestra la declaración de una nueva plantilla para un Botón, llamada ‘miEstilo’.  Dentro de esta Plantilla se declara un TextBlock el cual pone en su propiedad Text el valor de la propiedad Height del control en donde se está aplicando la Plantilla (botón ‘btn’):</p>
<div id="codeSnippetWrapper" style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; max-height: 200px; font-size: 8pt; cursor: text;">
<div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">Style</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="miEstilo"</span> <span style="color: #ff0000;">TargetType</span><span style="color: #0000ff;">="Button"</span><span style="color: #0000ff;">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;">            <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">Setter</span> <span style="color: #ff0000;">Property</span><span style="color: #0000ff;">="Width"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="150"</span> <span style="color: #0000ff;">/&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;">            <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">Setter</span> <span style="color: #ff0000;">Property</span><span style="color: #0000ff;">="Template"</span><span style="color: #0000ff;">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;">                <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">Setter.Value</span><span style="color: #0000ff;">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;">                    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">ControlTemplate</span><span style="color: #0000ff;">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;">                        <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">Border</span> <span style="color: #ff0000;">BorderBrush</span><span style="color: #0000ff;">="Red"</span> <span style="color: #ff0000;">BorderThickness</span><span style="color: #0000ff;">="5"</span><span style="color: #0000ff;">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;">                            <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;">                                <span style="color: #008000;">&lt;!--RelativeSource:  TemplatedParent--&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;">                                <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">TextBlock</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="{Binding Path=Height, RelativeSource={RelativeSource TemplatedParent}}"</span> <span style="color: #0000ff;">/&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;">                                <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">ContentPresenter</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Center"</span> <span style="color: #0000ff;">/&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;">                            <span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;">                        <span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">Border</span><span style="color: #0000ff;">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;">                    <span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">ControlTemplate</span><span style="color: #0000ff;">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;">                <span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">Setter.Value</span><span style="color: #0000ff;">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;">            <span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">Setter</span><span style="color: #0000ff;">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;">        <span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">Style</span><span style="color: #0000ff;">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"></pre>
<p><!--CRLF--></p>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;">....</pre>
<p><!--CRLF--></p>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"></pre>
<p><!--CRLF--></p>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">Button</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="btn"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="70"</span> <span style="color: #ff0000;">VerticalAlignment</span><span style="color: #0000ff;">="Top"</span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;">                    <span style="color: #ff0000;">Content</span><span style="color: #0000ff;">="Botón con Template"</span> <span style="color: #ff0000;">Style</span><span style="color: #0000ff;">="{StaticResource miEstilo}"</span> <span style="color: #0000ff;">/&gt;</span></pre>
<p><!--CRLF--></div>
</div>
<p>Cabe mencionar que esta opción es similar a utlizar {TemplateBinding} dentro de la Plantilla.</p>
<h2>Resumen</h2>
<p>Las nuevas características de Enlace presentes en Silverlight 3 Beta 1 extienden la funcionalidad y abren nuevas oportunidades para el desarrollo de aplicaciones con esta plataforma.</p>
<p>Para ver una aplicación en vivo que demuestra los conceptos expuestos <a href="http://silverlight.services.live.com/invoke/76819/RelativeSource%20Demo/iframe.html" target="_blank">pueden revisarla aquí</a> (el plugin de Silverlight 3 Beta 1 es requerido).</p>
]]></content:encoded>
			<wfw:commentRss>http://rdiazconcha.com/2009/05/silverlight-3-beta-1-enlace-relativesource/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

