반응형

UserControl 3

[WPF] 여러 Enum 상태에 따라 선택적으로 UserControl 표시하기

WPF에서 사용자 인터페이스를 개발하다 보면, 여러 상황에 따라 다양한 UserControl을 동적으로 표시해야 할 때가 있습니다. 이런 경우, Enum 상태에 따라 UserControl을 선택적으로 표시하는 방법을 사용할 수 있습니다. 이 이번 포스팅에서는 DataTemplate 및 DataTemplateSelector를 사용하여 여러 Enum 상태에 따라 UserControl을 표시하는 방법을 알아봅니다. 1. Enum 정의 public enum Status { First, Second, Third } 2. 각 상태에 대한 UserControl 정의 예를 들어, FirstControl.xaml, SecondControl.xaml, ThirdControl.xaml 파일을 각각 생성하여 다음과 같이 각 ..

프로그래밍/WPF 2023.04.12

[WPF] Usercontrol 사용 시, 디자이너 Exception 문제

Usercontrol을 이용하여 화면을 구성할때, Designer에 오류가 뜨면서 화면을 못볼때가 있다. 이유는 디자이너가 Usercontrol을 할때 생성자를 들어가서 작업을 해서 생기는 문제라나 뭐라나.. 여튼 디자이너모드일 경우 생성자 처리를 안해주면된다. UserControl 생성자에 InitializeComponent위에 아래와 같은 코드를 집어넣어주면된다. if (DesignerProperties.GetIsInDesignMode(this)) return;

프로그래밍/WPF 2022.08.04

[WPF] UserControl DependencyProperty 설정과 Binding 방법

자주 쓰이는 UserControl을 만들 때, 해당 컨트롤을 바딩인 속성 설정과 실제 바인딩 방법에 대해 알아본다. Usercontrol xaml cs namespace WintexMonitoring.View { /// /// MaterialCard.xaml에 대한 상호 작용 논리 /// public partial class MaterialCard : UserControl { public string Title { get { return (string)GetValue(TitleValueProperty); } set { SetValue(TitleValueProperty, value); } } public static readonly DependencyProperty TitleValueProperty = D..

프로그래밍/WPF 2021.07.21
반응형