■ RelativeSource 태그 확장 사용하기

----------------------------------------------------------------------------------------------------

<StackPanel

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    TextBlock.FontSize="12" >

    <StackPanel

        HorizontalAlignment="Center"

        Orientation="Horizontal">

        <TextBlock Text="This TextBlock has a FontFamily of " />

        <TextBlock Text="{Binding RelativeSource={RelativeSource self}, Path=FontFamily}" /> <!-- 바인딩 엘리먼트-->

        <TextBlock Text=" and a FontSize of " />

        <TextBlock Text="{Binding RelativeSource={RelativeSource self}, Path=FontSize}" /> <!-- 바인딩 엘리먼트-->

    </StackPanel>

    <StackPanel

        HorizontalAlignment="Center"

        Orientation="Horizontal">

        <TextBlock Text="This TextBlock is inside a StackPanel with " />

        <TextBlock Text= "{Binding RelativeSource={RelativeSource AncestorType={x:Type StackPanel}}, Path=Orientation}" /> <!-- 바인딩 엘리먼트의 부모 엘리먼트 -->

        <TextBlock Text=" orientation" />

    </StackPanel>

    <StackPanel

        HorizontalAlignment="Center"

        Orientation="Horizontal">

        <TextBlock Text="The parent StackPanel has " />

        <TextBlock Text= "{Binding RelativeSource={RelativeSource AncestorType={x:Type StackPanel}, AncestorLevel=2}, Path=Orientation}" /> <!-- 바인딩 엘리먼트의 조부모 엘리먼트 -->

        <TextBlock Text=" orientation" />

    </StackPanel>

</StackPanel>

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG