c#/WPF

[WPF] UserControl / CustomControl

Heeyeon Choi 2023. 4. 13. 11:09
728x90

<UserControl >

1.  새로운 WPF 창을 솔루션 UserControls 폴더에 생성

2. MainWindow로 가서 도구상자에 새로운 WPF 창이 생성된 것을 확인

3. ThreeControls 코드에 의존 속성 등록

4. ThreeControls XAML 이름 지정

5. MainWindow 에서 Label MyText 값 지정

6. ThreeControls(usercontrol) 에 Button 추가

 

7. ThreeControls 코드에 의존속성 추가

: ICommand 리턴, 기본값은 지워주기 

8. MainWindow에 MyCommand 값 추가

<CustomControl >

1.새로운 WPF창을 MyLabel 이라는 이름으로 생성 

2. 태그를 Label 로 변경

3. BackGround Color=Black / ForeGround Color=White / Content=mytext로 변경

4. MainWindow.xaml에 MyLabel 놓기 

728x90