C#/WPF
WPF tutorial - Command-line parameters in WPF
광그로
2017. 6. 20. 15:42
Command-line parameter(명령줄 인수)
http://www.wpf-tutorial.com/wpf-application/command-line-parameters/
Command-line parameter는 시작하고자 하는 응용프로그램에 parameter set를 전달할 수 있는 테크닉입니다.
Command-line parameter는 Startup event를 통하여 응용프로그램에 전달됩니다.
1 2 3 4 5 6 | <Application x:Class="WpfTutorialSamples.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Startup="Application_Startup"> <Application.Resources></Application.Resources> </Application> | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | using System; using System.Collections.Generic; using System.Windows; namespace WpfTutorialSamples { public partial class App : Application { private void Application_Startup(object sender, StartupEventArgs e) start event로 e라는 이름으로 전달됩니다. e라는 속성은 Args라는 문자열을 갖습니다. Command-line parameter는 공백으로 구분됩니다. { MainWindow wnd = new MainWindow(); if(e.Args.Length == 1) MessageBox.Show("Now opening file: \n\n" + e.Args[0]); wnd.Show(); } } } | cs |
응용프로그램 시작 시, command-line parameter에 해당하는 file을 같이 실행한다.
[프로젝트 이름]우클릭 - [속성] - [디버그] - [명령줄 인수] - C:\Windows\win.ini 입력