- 부모요소에서 상속받은 속성 사용시 붙임(Attached) 속성 사용
- SetValue() : 설정하기
- GetValue() : 가져오기
MainPage.xaml |
[그림 52-1] <Canvas Background="red" Width="400" Height="300" x:Name="LayoutRoot"> <Rectangle x:Name="rect" Width="50" Height="50" Fill="Yellow" Stroke="Blue" StrokeThickness="1" Canvas.Left="100" Canvas.Top="50"> </Rectangle> </Canvas> |
MainPage.xaml |
public MainPage() { InitializeComponent(); //이벤트 등록 this.rect.MouseLeftButtonDown+= new MouseButtonEventHandler(rect_MouseLeftButtonDown); } privatebool flag; void rect_MouseLeftButtonDown(object sender, MouseButtonEventArgse) { //캔버스의 배경색 가져오기 : GetValue Brushc = this.LayoutRoot.Background; //사각형의 배경색 가져오기 Brushr = this.rect.Fill; //캔버스의 배경색 가져오기 this.LayoutRoot.Background= r; //사각형의 배경색을 설정하기 this.rect.Fill= c; //[!]붙임속성 set/get //<RectangleCanvas.Left="값"/> intx = Convert.ToInt32(rect.GetValue(Canvas.LeftProperty)); if(flag == true) //왼쪽으로 100px 이동 { //현재 좌표 값 -100 this.rect.SetValue(Canvas.LeftProperty, Convert.ToDouble(x- 100)); } else//오른쪽으로 100px 이동 { //현재 좌표 값 +100 this.rect.SetValue(Canvas.LeftProperty, Convert.ToDouble(x+ 100)); } } |
결과화면 |
[그림 52-2] |
'Silverlight' 카테고리의 다른 글
54.SilverLight3 - RepeatButton (0) | 2009.12.02 |
---|---|
53.SilverLight3 - HyperlinkButton (0) | 2009.12.02 |
51.SilverLight3 - RoutedEventArgs (0) | 2009.12.01 |
50.SilverLight3 - InkPresenter (0) | 2009.12.01 |
49.SilverLight3 - DragAndDrop (0) | 2009.12.01 |
Comments