Blog Content

    티스토리 뷰

    52.SilverLight3 - AttachedProperty

    반응형
    AttachedProperty
    - 부모요소에서 상속받은 속성 사용시  붙임(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; // true/false ()

    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