반응형

전체 글 134

[C#] Path에서 각종 경로 추출

자주 쓰이는 것들을 아래와 같이 정리해보았다. string path = @"T:\test_path\path1\item.json"; // 파일명 추출 Path.GetFileName(path); // item.json // 확장자 추출 Path.GetExtension(path); // .json // 확장자 없이 파일명만 Path.GetFileNameWithoutExtension(path); // item // 경로만 추출 Path.GetDirectoryName(path); // T:\test_path\path1 // 현재 실행 경로 가져오기 System.IO.Directory.GetCurrentDirectory(); System.Environment.CurrentDirectory;

프로그래밍/C# 2021.06.15

[WPF] ItemControl에서 Item Index binding

ItemControl 등에서 각 itemsSource에 있는 파일을 삭제 처리나 수정 처리 할 때, 방법에 따라 다양하지만 해당 ItemTemplate에 추가나 삭제 버튼을 만들어 처리하는게 일반적이다. 이때 해당 ItemsSource의 Index값을 가져와서 처리하는 방법을 알아보자. ViewModel class ConfigViewModel : DialogViewModelBase { private string _address; public string Address { get { return _address; } set { SetProperty(ref _address, value); } } public ObservableCollection IP { get; set; } public DelegateCom..

프로그래밍/WPF 2021.05.11

[C#] 디자인패턴 - Singleton

간단하게 싱글톤을 클래스를 선언하는 방법을 알아본다. 나는 주로 싱글톤을 쓸 때, 다양한 화면에서 데이터가 공유 관리되어야 하거나 통신용 객체를 만들거나, DAO생성을 할 때 주로 쓴다. 싱글톤 객체 생성 public sealed class DataManager { private static readonly DataManager _instance = new DataManager(); public static DataManager GetInstance() { return _instance; } private DataManager() { } } 객체 불러오기 class MainWindowViewModel : BindableBase { private DataManager _dm; public MainWindo..

프로그래밍/C# 2021.05.11

[C#] 객체의 값 변경된 내용만 추출하기

Log 처리에 모든 값을 다 넣으면 좋긴하겠지만 객체의 내용이 너무나 많다면 보기에도 부담되고 데이터 쌓을때도 부담된다. 어떻게 할까 고민하다가 타겟과 소스를 기준으로 양 객체 데이터를 기반으로 변경된 값만 추출하는 함수를 만들었다. private Dictionary DictionaryFromType(object atype) { if (atype == null) return new Dictionary(); Type t = atype.GetType(); PropertyInfo[] props = t.GetProperties(); Dictionary dict = new Dictionary(); foreach (PropertyInfo prp in props) { object value = prp.GetValue..

프로그래밍/C# 2021.05.11

[WPF] Value Converter

바인딩 처리를 하다보면 값에 따라 화면에 바인딩 되어야하는 값이 달라야 할때가 있다. 예를들어 bool 값을 이용하여 visible처리 할 때나, 퍼센트 값에 따라 폰트 컬러가 달라진다거나 하는 기타 등등의 요소가 존재한다. 이를 위한 Value Converter 사용법은 아래와 같다. ViewModel에 컨버터 클래스를 선언한다. public abstract class BaseOnewayConverter : MarkupExtension, IValueConverter { public BaseOnewayConverter() { } // source to binding target public abstract object Convert(object value, Type targetType, object pa..

프로그래밍/WPF 2021.05.10

[WPF] MVVM에서 IDialogService 사용

mvvm을 사용할 때, Dialog용 Service를 만들어서 사용하는 방법을 기술하겠다. 위의 구조대로 만들 예정이다. 만약 새로운 화면이 필요하다면 커스텀 DialogView를 이용하여 처리하면 된다. IDialogWindow.cs namespace CounterMonitor.Dialogs.Service { public interface IDialogWindow { bool? DialogResult { get; set; } object DataContext { get; set; } bool? ShowDialog(); } } 창을 띄울 화면 생성 DialogWindow.xaml 해당 위의 인터페이스를 상속하자 DialogWindow.xaml.cs using System.Windows; namespace..

프로그래밍/WPF 2021.05.10

[Linux] Timezone 변경하기

리눅스 터미널에서 date를 입력하면 현재 시간과 타임존이 나온다. $ date Mon May 10 02:58:58 AST 2021 타임존을 변경하기 위해서 타임존 리스트를 가지고 와보자 $ timedatectl list-timezones 혹은 나는 America쪽만 확인하고 싶다. $ timedatectl list-timezones | grep "America" America/Adak America/Anchorage America/Anguilla America/Antigua America/Araguaina America/Argentina/Buenos_Aires America/Argentina/Catamarca America/Argentina/Cordoba America/Argentina/Jujuy Am..

[WPF] IGrouping 데이터 바인딩 하기

LINQ를 사용하다보면 group를 사용하여 그룹화를 시켜줄 때가 많다. 이때, group 사용 시에 IGrouping Interface를 반환받게 되는데 이것을 데이터 바인딩 하는 방법을 알아본다. Model DTO public class IoTStatus : BindableBase { private int _line; public int Line { get { return _line; } set { SetProperty(ref _line, value); } } private int _table; public int Table { get { return _table; } set { SetProperty(ref _table, value); } } } Service public async Task GetI..

프로그래밍/WPF 2021.05.06
반응형