Microsoft MVP성태의 닷넷 이야기
안녕하세요. 질문이 있습니다. [링크 복사], [링크+제목 복사],
조회: 17710
글쓴 사람
POCO
홈페이지
첨부 파일
 

wpf에서 유저컨트롤을 만들고 바인딩을 거는데 궁금점이 있어서 질문 드립니다.

<UserControl x:Class="MyTest.Cell"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d"
             d:DesignHeight="90" d:DesignWidth="100" Name="Cell">

<TextBlock x:Name="tb_Age" Text="{Binding Age}" />

</UserControl>


cs코드
public static readonly DependencyProperty AgeProperty =
            DependencyProperty.Register("Age", typeof(string), typeof(UserControl), new PropertyMetadata(null));
public string Age
{
            get { return (string)GetValue(AgeProperty); }
            set { SetValue(AgeProperty, value); }
}


위 처럼 했을 경우 바인딩할 수 없는데 당연히 DataContext가 지정되지 않아서 바인딩이 안된다고 이해하고 있습니다.

하지만 xaml에서 바인딩에 ,ElementName=Cell를 추가해 주면 바인딩이 됩니다.

ElementName에 Cell은 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 이 부분인데 이 부분 하나추가로써 어떻게 바인딩이 이루어 졌는지 궁금합니다.

답변부탁드립니다.








[최초 등록일: ]
[최종 수정일: 3/6/2014]


비밀번호

댓글 작성자
 



2014-03-06 10시02분
제가 질문을 잘못 이해하고 있는지도 모르겠는데요. ElementName의 "Cell"은 UserControl 열림 태그의 마지막에 Name="Cell"로 지정되어서 가능한 것입니다.
정성태

NoWriterDateCnt.TitleFile(s)