728x90
반응형

Custom FrameworkElement 정의하고 사용하는 방법입니다.

NumberProperty(숫자)를 의존속성으로가지며 이를 화면에 보여주는 FrameworkElement 를 정의합니다.

 

CustomElement.cs

using System.Globalization;

using System.Windows;

using System.Windows.Media;

 

namespace WpfApp

{

    class CustomElement : FrameworkElement

    {

        /// <summary>

        /// 화면에 표시될 숫자에 대한 의존 속성입니다.

        /// </summary>

        public static DependencyProperty NumberProperty;

 

        /// <summary>

        /// 화면에 표시될 숫자 값입니다.

        /// </summary>

        public double Number

        {

            set

            {

                SetValue(NumberProperty, value);

            }

            get

            {

                return (double)GetValue(NumberProperty);

            }

        }

 

        /// <summary>

        /// 생성자입니다.

        /// </summary>

        static CustomElement()

        {

            // DependencyProperty 를 생성합니다.

            NumberProperty = DependencyProperty.Register

            (

                "Number",

                typeof(double),

                typeof(CustomElement),

                new FrameworkPropertyMetadata

                (

                    0.0,

                    FrameworkPropertyMetadataOptions.AffectsRender

                )

            );

        }

 

 

        /// <summary>

        /// FrameworkElement 의 크기를 정의합니다.

        /// </summary>

        /// <param name="sizeAvailable">자식 요소에 제공할 수 있는 사용 가능한 크기입니다.</param>

        /// <returns></returns>

        protected override Size MeasureOverride(Size sizeAvailable)

        {

            return new Size(200, 50);

        }

 

        /// <summary>

        /// 레이아웃시스템에서 감독하는 렌더링 작업에 참여합니다.

        /// Number 를 화면에 표시합니다.

        /// </summary>

        /// <param name="dc">특정 요소에 대 한 그리기 지침입니다</param>

        protected override void OnRender(DrawingContext dc)

        {

            SolidColorBrush mySolidColorBrush = new SolidColorBrush() { Color = Colors.LimeGreen };

            Pen myPen = new Pen(Brushes.LimeGreen, 1);

            Rect myRect = new Rect(0, 0, 200, 50);

 

            dc.DrawRectangle(mySolidColorBrush, myPen, myRect);

 

            dc.DrawText

            (

                new FormattedText

                (

                    Number.ToString(),

                    CultureInfo.CurrentCulture,

                    FlowDirection.LeftToRight,

                    new Typeface("Arial"),

                    12,

                    SystemColors.WindowTextBrush

                ),

                new Point(0, 0)

            );

        }

    }

}

 

 

정의한 CustomElement 를 아래와 같이 사용하면 Number 에 정의한 내용이 화면에 표시됩니다.

<Window x:Class="WpfApp.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

        xmlns:src="clr-namespace:WpfApp"

        mc:Ignorable="d"

        Title="MainWindow" Height="450" Width="800">

    <DockPanel>

        <src:CustomElement Number="50"/>

    </DockPanel>

</Window>

 

 

 

728x90
반응형
728x90
반응형

Binding 은 컨트롤과 엘리먼트를 데이터에 연결시켜주는 기술로

타겟 컨트롤 변화에 따라 소스 컨트롤에 변화를 줄 수 있습니다.

 

아래 예시를 보면 ScrollBar 에 변화값을 Label 의 Content 에 반영하고 있는 코드입니다.

 

 

        <StackPanel>

            <ScrollBar

                 Name="scrollBar"

                 Orientation="Horizontal"

                 Margin="24"

                 Maximum="100"

                 LargeChange="10"

                 SmallChange="1" />

            <Label

                 HorizontalAlignment="Center"

                 Content="{Binding ElementName=scrollBar, Path=Value}" />

        </StackPanel>

 

 

아래처럼 DataContext 를 이용해 자식요소들의 ElementName 을 미리 정의할수 있습니다.

 

        <StackPanel DataContext="{Binding ElementName=scrollBar}">

            <ScrollBar

                 Name="scrollBar"

                 Orientation="Horizontal"

                 Margin="24"

                 Maximum="100"

                 LargeChange="10"

                 SmallChange="1" />

            <Label

                 HorizontalAlignment="Center"

                 Content="{Binding Path=Value}" />

            <Button

                 HorizontalAlignment="Center"

                 Margin="24"

                 FontSize="{Binding Path=Value}">

                Bound Button

            </Button>

        </StackPanel>

 

Label 과 Button 에 ElementName 을 지정하지 않아도 부모 StakPanel 의 DataContext 에 정의된 ElementName 을 사용하게 됩니다.

 

 

 

아래처럼 ScrollBar 가 StakPanel 을 벗어나도 상관없다.

 

<Window x:Class="WpfApp.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

        mc:Ignorable="d"

        Title="MainWindow" Height="450" Width="800">

    <StackPanel x:Name="stackPanel">

        <ScrollBar

                 Name="scrollBar"

                 Orientation="Horizontal"

                 Margin="24"

                 Maximum="100"

                 LargeChange="10"

                 SmallChange="1" />

        <StackPanel DataContext="{Binding ElementName=scrollBar}">

            <Label

                 HorizontalAlignment="Center"

                 Content="{Binding Path=Value}" />

            <Button

                 HorizontalAlignment="Center"

                 Margin="24"

                 FontSize="{Binding Path=Value}">

                Bound Button

            </Button>

        </StackPanel>

    </StackPanel>

</Window>

 

 

 

 

728x90
반응형
728x90
반응형

PageFunction 은 쉽게 설명하면 Navigation 구조에서 리턴이 있는 페이지 라고 보면 되겠다

회원가입절치를 진행할 때 주소입력시 주소를 조회하기위한 화면이 뜨고

주소검색이 끝나면 다시 원래 페이지로 돌아와 주소가 입력되게 되는데

주소를 조회하기 위한 화면이 PageFunction 으로 구현하면 된다.

 

MainWindow.xaml

<Window x:Class="WpfApp.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

        mc:Ignorable="d"

        WindowStartupLocation="CenterScreen"

        Title="MainWindow" Height="400" Width="250">

    <Grid>

        <Frame Source="MainPage.xaml" />

    </Grid>

</Window>

 

 

MainWindow.xaml.cs

using System.Windows;

 

namespace WpfApp

{

    public partial class MainWindow : Window

    {

        public MainWindow()

        {

            InitializeComponent();

        }

    }

}

 

MainPage.xaml

<Page x:Class="WpfApp.MainPage"

      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

      mc:Ignorable="d"

      d:DesignHeight="450" d:DesignWidth="250"

      Title="Page1" Background="White">

    <StackPanel>

        <StackPanel Orientation="Horizontal" Margin="5">

            <Label Content="이름 : " VerticalAlignment="Center" />

            <TextBox Background="LightGray" VerticalAlignment="Center" Width="100"/>

        </StackPanel>

        <Button Name="addressButton" Content="주소입력" Click="AddressButton_Click" />

        <StackPanel Orientation="Horizontal" Margin="5">

            <Label Content="주소 : " VerticalAlignment="Center" />

            <TextBlock Name="addressTextBlock" Background="LightGray" Width="200" VerticalAlignment="Center"/>

        </StackPanel>

    </StackPanel>

</Page>

 

 

* MainPage 에서 PageFunction 페이지를 호출하고 입력값을 리턴 받는다.

 

MainPage.xaml.cs

using System.Windows.Controls;

using System.Windows.Navigation;

 

namespace WpfApp

{

    public partial class MainPage : Page

    {

        public MainPage()

        {

            InitializeComponent();

        }

 

        /// <summary>

        /// 주소입력 버튼 클릭이벤트입니다.

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void AddressButton_Click(object sender, System.Windows.RoutedEventArgs e)

        {

            InputAddressPage inputAddressPage = new InputAddressPage();

 

            inputAddressPage.Return += new ReturnEventHandler<string>(InputAddressPage_Return);

 

            NavigationService.Navigate(inputAddressPage);

        }

 

        /// <summary>

        /// InputAddressPage 가 닫혔을 때 결과값을 받아 처리하는 이벤트입니다.

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        void InputAddressPage_Return(object sender, ReturnEventArgs<string> e)

        {

            this.addressTextBlock.Text = e.Result;

        }

    }

}

 

 

InputAddressPage.xaml

<PageFunction x:Class="WpfApp.InputAddressPage"

              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

              xmlns:sys="clr-namespace:System;assembly=mscorlib"

              x:TypeArguments="sys:String"

              mc:Ignorable="d"

              d:DesignHeight="300" d:DesignWidth="300"

              Title="InputAddressPage" Background="Yellow">

    <StackPanel>

        <TextBlock Name="addressTextBlock" Text="주소를 입력하세요" VerticalAlignment="Center"/>

        <TextBox Name="addressTextBox" VerticalAlignment="Center"/>

        <Button Name="inputButton" Content="입력" Click="InputButton_Click" />

    </StackPanel>

</PageFunction>

 

 

InputAddressPage.xaml.cs

using System.Windows;

using System.Windows.Navigation;

 

namespace WpfApp

{

    public partial class InputAddressPage : PageFunction<string>

    {

        public InputAddressPage()

        {

            InitializeComponent();

        }

 

        /// <summary>

        /// 입력 버튼 클릭시 이벤트입니다.

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void InputButton_Click(object sender, RoutedEventArgs e)

        {

            // MainPage 로 값을 넘겨줍니다.

            OnReturn(new ReturnEventArgs<string>(this.addressTextBox.Text));

        }

    }

}

 

 

       

 

 

 

728x90
반응형

'WPF' 카테고리의 다른 글

[WPF] Custom FrameworkElement 사용하기  (0) 2020.07.10
[WPF] Binding  (0) 2020.07.09
[WPF] PageFunction  (0) 2020.07.09
[WPF] 화면 중앙에 출력하기, content 에 맞춰 화면 크기 조정하기  (0) 2020.07.09
[WPF] static member 사용하기  (0) 2020.07.09
[WPF] ContextMenu  (0) 2020.07.08
728x90
반응형

- 화면 중앙에 출력하기

 

WindowStartupLocation="CenterScreen"

 

- content 에 맞춰 화면 크기 조정하기

 

SizeToContent="WidthAndHeight"

 

 

 

<Window x:Class="WpfApp2.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

        xmlns:src="clr-namespace:WpfApp"

        mc:Ignorable="d"

        WindowStartupLocation="CenterScreen"

        SizeToContent="WidthAndHeight"

        Title="MainWindow" Height="400" Width="600">

    <DockPanel>

    </DockPanel>

</Window>

 

 

 

 

728x90
반응형

'WPF' 카테고리의 다른 글

[WPF] Binding  (0) 2020.07.09
[WPF] PageFunction  (0) 2020.07.09
[WPF] 화면 중앙에 출력하기, content 에 맞춰 화면 크기 조정하기  (0) 2020.07.09
[WPF] static member 사용하기  (0) 2020.07.09
[WPF] ContextMenu  (0) 2020.07.08
[WPF] xml 로드하기  (0) 2020.07.08
728x90
반응형

코드 비하인드에 정의한 static member 를 사용하는 방법입니다.

 

먼저 아래처럼 static member 를 선언합니다.

 

using System.Windows;

 

namespace WpfApp

{

    public partial class MainWindow : Window

    {

        public static double WidthCanvas = 5 * 96;

        public static double HeightCanvas = 7 * 96;

 

        public MainWindow()

        {

            InitializeComponent();

        }

    }

}

 

 

그리고 xaml 단에서 아래 굵게 표시된 부분처럼 사용하면 됩니다.

 

<Window x:Class="WpfApp.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

        xmlns:src="clr-namespace:WpfApp"

        mc:Ignorable="d"

        Title="MainWindow" Height="400" Width="600">

    <DockPanel>

        <ScrollViewer VerticalScrollBarVisibility="Auto">

            <InkCanvas Name="inkcanv"

                    Width="{x:Static src:MainWindow.WidthCanvas}"

                    Height="{x:Static src:MainWindow.HeightCanvas}"

                    Background="LemonChiffon">

                <Line

                     Stroke="Red"

                     X1="0.875in"

                     Y1="0"

                     X2="0.875in"

                     Y2="{x:Static src:MainWindow.HeightCanvas}" />

                <Line

                     Stroke="Red"

                     X1="0.9375in"

                     Y1="0"

                     X2="0.9375in"

                     Y2="{x:Static src:MainWindow.HeightCanvas}" />

            </InkCanvas>

        </ScrollViewer>

    </DockPanel>

</Window>

 

 

 

* 아래처럼 작성후 밑줄이 그어지는 경우가 있는데

 

 

이때는 다시 빌드가 필요합니다.

 

* 혹 코드 상에 다른 에러가 있다면 빌드가 되지않아 밑줄그어진 상태가 유지되니 반드시

에러를 모두 확인 후 빌드 해야합니다.

 

728x90
반응형
728x90
반응형

특정 컨트롤에 ContextMenu 를 만드는 방법입니다.

MainWindow.xaml

<Window x:Class="WpfApp.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

        xmlns:local="clr-namespace:WpfApp"

        mc:Ignorable="d"

        Title="MainWindow" Height="400" Width="600">

    <TextBlock

 Name="txtblk"

 FontSize="24pt"

 HorizontalAlignment="Center"

 VerticalAlignment="Center"

 ToolTip="Right click to display context menu">

 TextBlock with Context Menu

        <TextBlock.ContextMenu>

            <ContextMenu MenuItem.Click="MenuItemOnClick">

                <MenuItem Header="Red" />

                <MenuItem Header="Orange" />

                <MenuItem Header="Yellow" />

                <MenuItem Header="Green" />

                <MenuItem Header="Blue" />

                <MenuItem Header="Indigo" />

                <MenuItem Header="Violet" />

            </ContextMenu>

        </TextBlock.ContextMenu>

    </TextBlock>

</Window>

 

 

MainWindow.xaml.cs

using System.Windows;

using System.Windows.Controls;

using System.Windows.Media;

 

namespace WpfApp

{

    /// <summary>

    /// MainWindow.xaml에 대한 상호 작용 논리

    /// </summary>

    public partial class MainWindow : Window

    {

        public MainWindow()

        {

            InitializeComponent();

        }

 

        void MenuItemOnClick(object sender, RoutedEventArgs args)

        {

            string str = (args.Source as MenuItem).Header as string;

            Color clr = (Color)ColorConverter.ConvertFromString(str);

            txtblk.Foreground = new SolidColorBrush(clr);

        }

    }

}

 

 

 

728x90
반응형
728x90
반응형

xml string 을 load 하여 화면에 보여주는 코드입니다.

(내용은 찰스패졸드 책 내용 인용)

 

using System.IO;

using System.Windows;

using System.Windows.Markup;

using System.Xml;

 

namespace WpfApp

{

    /// <summary>

    /// MainWindow.xaml에 대한 상호 작용 논리

    /// </summary>

    public partial class MainWindow : Window

    {

        public MainWindow()

        {

            InitializeComponent();

 

            string strXml = @"

<FlowDocument xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'

              xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'

              TextAlignment='Left'>

    <Paragraph TextAlignment='Center' FontSize='32' FontStyle='Italic'

               LineHeight='24'>

        KJUN.KR

    </Paragraph>

    <Paragraph TextAlignment='Center'>

        &#x00A9; 2020 by kjun

    </Paragraph>

    <Paragraph FontSize='16pt' FontWeight='Bold' LineHeight='16'>

        Introduction

    </Paragraph>

    <Paragraph>

        KJUN.KR is a sample program from kjun

        <Italic>

            Applications = Code + Markup:

            A Guide to the Microsoft Windows Presentation Foundation

        </Italic>

        published by Microsoft Press in 2020.

        XAML Cruncher provides a convenient way to learn about and experiment

        with XAML, the Extensible Application Markup Language.

    </Paragraph>

    <Paragraph>

        XAML Cruncher consists of an Edit section (in which you enter and edit

        a XAML document) and a Display section that shows the object created

        from the XAML. If the XAML document has errors, the text is displayed

        in red and the status bar indicates the problem.

    </Paragraph>

    <Paragraph>

        Most of the interface and functionality of the edit section of

        XAML Cruncher is based on Windows Notepad.

        The

        <Bold>Xaml</Bold> menu provides additional features.

    </Paragraph>

    <Paragraph FontSize='16pt' FontWeight='Bold' LineHeight='16'>

        Xaml Menu

    </Paragraph>

    <Paragraph>

        The

        <Bold>Orientation</Bold> menu item lets you choose whether you

        want the Edit and Display sections of XAML Cruncher arranged

        horizontally or vertically.

    </Paragraph>

    <Paragraph>

        The

        <Bold>Tab Spaces</Bold> menu item displays a dialog box that lets

        you choose the number of spaces you want inserted when you press the

        Tab key. Changing this item does not change any indentation

        already in the current document.

    </Paragraph>

    <Paragraph>

        There are times when your XAML document will be so complex that it

        takes a little while to convert it into an object. You may want to

        <Bold>Suspend Parsing</Bold> by checking this item on the

        <Bold>Xaml</Bold> menu.

    </Paragraph>

    <Paragraph>

        If you've suspended parsing, or if you want to reparse the XAML file,

        select

        <Bold>Reparse</Bold> from the menu or press F6.

    </Paragraph>

    <Paragraph>

        If the root element of your XAML is

        <Italic>Window</Italic> ,

        XAML Cruncher will not be able to display the

        <Italic>Window</Italic>

        object in its own window.

        Select the

        <Bold>Show Window</Bold> menu item or press F7 to view

        the window.

    </Paragraph>

    <Paragraph>

        When you start up XAML Cruncher (and whenever you select

        <Bold>New</Bold> from the

        <Bold>File</Bold> menu), the Edit window

        displays a simple startup document.

        If you want to use the current document as the startup document,

        select the

        <Bold>Save as Startup Document</Bold> item.

    </Paragraph>

</FlowDocument>

";

 

            StringReader strreader = new StringReader(strXml);

            XmlTextReader xmlreader = new XmlTextReader(strreader);

            object obj = XamlReader.Load(xmlreader);

 

            Content = obj;

        }

 

    }

}

 

 

 

 

 

아래처럼 XML 에 frame 를 이용해 xml 파일을 지정할수도 있다.

 

<Window x:Class="WpfApp.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

        xmlns:local="clr-namespace:WpfApp"

        mc:Ignorable="d"

        Title="MainWindow" Height="400" Width="600">

    <Frame Source="kjunkr.xaml" />

</Window>

 

 

 

728x90
반응형

'WPF' 카테고리의 다른 글

[WPF] static member 사용하기  (0) 2020.07.09
[WPF] ContextMenu  (0) 2020.07.08
[WPF] xml 로드하기  (0) 2020.07.08
[WPF] xml 16진수 값 0x0C은(는) 잘못된 문자입니다.  (0) 2020.07.08
[WPF] Hyperlink  (0) 2020.07.08
[WPF] Custom RoutedUICommand 만들기  (0) 2020.07.07
WPF
728x90
반응형

xml 로드시

"xml 16진수 값 0x0C은(는) 잘못된 문자입니다. "

이라는 에러가 발생했다.

원인은 원본데이터에 null byte가 있어서 XML문서가 깨지는거라고 한다.

아래처럼 xml string 을 아래 메서드를 통새 Replace 해주면 문제는 해결된다.

 

 

        public static string ReplaceHexadecimalSymbols(string txt)

        {

            string pattern = "[\x00-\x08\x0B\x0C\x0E-\x1F\x26]";

            return Regex.Replace(txt, pattern, "", RegexOptions.Compiled);

        }

 

 

728x90
반응형

'WPF' 카테고리의 다른 글

[WPF] ContextMenu  (0) 2020.07.08
[WPF] xml 로드하기  (0) 2020.07.08
[WPF] xml 16진수 값 0x0C은(는) 잘못된 문자입니다.  (0) 2020.07.08
[WPF] Hyperlink  (0) 2020.07.08
[WPF] Custom RoutedUICommand 만들기  (0) 2020.07.07
[WPF] TextBox 개행 가능하도록 하기  (0) 2020.07.07
728x90
반응형

HyperLink 를 삽입하는 코드입니다.

 

 

using System;

using System.Diagnostics;

using System.Windows;

using System.Windows.Documents;

using System.Windows.Navigation;

 

namespace WpfApp

{

    /// <summary>

    /// MainWindow.xaml에 대한 상호 작용 논리

    /// </summary>

    public partial class MainWindow : Window

    {

        public MainWindow()

        {

            InitializeComponent();

 

            Hyperlink hyperlink = new Hyperlink();

            hyperlink.Inlines.Add("kjun.kr");

            hyperlink.NavigateUri = new Uri("https://kjun.kr");

            hyperlink.RequestNavigate += Hyperlink_RequestNavigate;

            this.hyperLinkLabel.Content = hyperlink;

        }

 

        private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)

        {

            Process.Start(e.Uri.AbsoluteUri);

            e.Handled = true;

        }

    }

}

 

 

 

클릭하면 사이트로 이동합니다.

 

 

728x90
반응형
728x90
반응형

Custom RoutedUICommand 를 만드는 코드로

Ctrl+K 를 누른 경우 TextBox 에 'kjun.kr' 이 찍히도록 하는 예시코드입니다.

 

using System.Windows;

using System.Windows.Input;

 

namespace WpfApp

{

    /// <summary>

    /// MainWindow.xaml에 대한 상호 작용 논리

    /// </summary>

    public partial class MainWindow : Window

    {

        public MainWindow()

        {

            InitializeComponent();

 

            this.textBox.AcceptsReturn = true;

            this.textBox.AcceptsTab = true;

 

            InputGestureCollection inputGestureCollection = new InputGestureCollection();

            inputGestureCollection.Add(new KeyGesture(Key.K, ModifierKeys.Control));

 

            RoutedUICommand commandKjunkr = new RoutedUICommand("kjun.kr", "kjunkr", GetType(), inputGestureCollection);

            CommandBindings.Add(new CommandBinding(commandKjunkr, KjunkrOnExecute));

        }

 

        void KjunkrOnExecute(object sender, ExecutedRoutedEventArgs args)

        {

            this.textBox.SelectedText = "kjun.kr";

        }

    }

}

 

 

728x90
반응형

+ Recent posts