Programming/C#

Programming/C#

[OxyPlot] C# Custom Command Binding

1. Command 정의 및 Binding Oxyplot의 PlotController 에 원하는 이벤트에 대한 Command를 Binding 한다. 이를 위해서 어떤 데이터를 변수로 handle 할지를 정의한 Delegate를 선언한다. 그리고 원하는 이벤트에 Binding 을 한다. private PlotController BuildMainPlotcontroller() { var plotController = new PlotController(); // plotController.UnbindAll(); // Custom Command 함수를 위한 Delegate를 정의한다. HeatmapClicked = new DelegatePlotCommand((view, controller, args) => Hea..

Programming/C#

[C#] Setting Service with Configuration

1. 개요 Setting Service 를 구현하기 위해 사용되는 Package를 비교 분석한다. System.Configuration.ConfigurationManager 와 Microsoft.Extensions.Configuration 의 기능을 비교한다. 더보기 1. Historical Context: System.Configuration.ConfigurationManager: Part of the older .NET Framework. Commonly used to read settings from App.config for desktop apps and Web.config for ASP.NET apps. Built primarily for a world where apps had a single..

Programming/C#

[C#] Logging 서비스 활용하기

1. 개요 로깅 서비스를 통합관리하는 시스템으로 편리하게 소프트웨어 로깅을 기록하자. 2. 소개 여기에서는 .Net에서 사용할 수 있는 로깅 서비스로 NLog를 사용하려고 한다 간단한 설정에서 Dependency Injection 을 활용할 예정이다. 3. 구현하기 우선 Package 는 NLog와 NLog.Extension.Logging이 필요하다. NLog를 사용하기 위해서 Configuration 파일을 등록해야하는데 두가지 방법을 사용할 수 있다. # Configuration Config | NLog (nlog-project.org) NLog.config vs. appsettings.json 작성하는 방식의 차이일뿐 큰차이는 없다. 다만 NLog.config 를 사용할 경우에는 복잡한 layout..

Programming/C#

WPF Behavior.Wpf

버튼을 Click 한 이벤트를 ViewModel 의 Command 에 binding 하고, 이때 CommandParameter를 전달하는 방법이다. 이 때 전달하는 Parameter는 string 으로 입력을 하므로, 다른 타입으로 변환하여 전달하고 싶으면 Coverter를 정의해야한다. 간단하게 string to double converter를 구현하고 이를 CommandParameter의 내부 converter 속성에 conveter를 입력한다. 1, 2의 tag의 경우에는 CommandParameter는 string 으로만 입력할 수 있으므로, 매개변수를 string 또는 object 를 갖는 command 와 연결할 수 있다. 다른 것은 전달되는 타입만 다를뿐 값은 동일하다. 3번은 Command..

Programming/C#

Wpf dialog service

개별 view를 이용한 dialog Creating a dialog service in an MVVM application is a great way to show different types of dialogs (e.g., messaging, prompts, information windows) without directly depending on specific views from the ViewModel. This allows you to maintain separation of concerns and avoid tightly coupling the ViewModel to the UI. Here's a step-by-step guide on building a dialog service: 1. **..

Programming/C#

[C#] Array Conversion 성능 비교

1. 개요 Array 간의 데이터 타입 변환을 수행하고 성능을 비교한다. 2. 비교할 구현 코드 For loop Linq Select Array.ConvertAll [Test] public void TestConvertPerf() { PerfBenchmark bench = new PerfBenchmark("Convert Benchmark"); var intArr = RandomUtils.GenerateInt(500000); int repSize = 1000; bench.Start(); for (int i = 0; i < repSize; i++) { ToDoubleArray(intArr); bench.SaveCheckpoint(); } bench.Stop(); Console.WriteLine($"Avg, ..

Programming/C#

WPF 아키텍쳐

WPF 는 아래의 구성에서 빨간색 표시된 다이어그램이다. milcore 는 DirectX를 위한 코드이어서 native이고 나머지는 managed 코드이다. System.Threading.DispatcherObject DispatcherObject는 WPF의 대부분의 클래스의 부모클래스로 정의된다. 이는 여러개의 쓰레드간의 데이터를 주고받을 수 있도록 CLR 객체를 생성하여 STA 동작이 되도록 한다. Dispatcher를 통해서 메시지를 큐에 쌓아서 순차적으로 동작을 하면서 단일 쓰레드에서 UI를 제어 할 수 있도록 한다. 관련된 것이 cross thread exception, deadlock, race condition과 같은 문제를 방지하기 위한 것이다. System.Windows.Dependenc..

Programming/C#

WPF Style multiple controltemplate

WPF Style을 이용하여 여러개의 TargetType 에 대해서 각각의 ControlTemplate를 지정하는 방법이다. Style을 Control 에 지정하였을 때, Resource는 Target이 되는 Type별로 ControlTemplate을 정의한다. Style의 Template property 에는 style이 적용되는 control 의 TargetType 속성을 얻어와 Style.Resource 에서 매치되는 TargetType의 ControlTemplate를 적용할 수 있도록 한다. 이를 위해서 RelativeSource 의 Self 객체의 Path=TargetType 으로 값을 얻어와서 ControlTemplate의 TargetType에 binding 한다. 아래는 Button 에 St..

Programming/C#

Wpf toast message

Wpf toast message 활용하기 using Windows.Data.Xml.Dom; using Windows.UI.Notifications; public void ShowCustomizedToastNotification(string title, string message, string imageFilePath, string audioFilePath, int durationInSeconds) { // Set up the XML content for the toast notification var xml = $@" {title} {message} This is a long message that should wrap to multiple lines in the notification. param1=v..

Programming/C#

ControlTemplate & DataTemplate

개념 Templates: Templates in WPF are used to define the structure and appearance of controls. They provide a way to customize the look and feel of a control without changing its functionality. There are two main types of templates in WPF: a. ControlTemplate: A ControlTemplate allows you to redefine the entire visual appearance of a control, such as a Button, ListBox, or ComboBox. It is a blueprint..

RichardBang
'Programming/C#' 카테고리의 글 목록