첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
다운로드

▶ MainWindow.xaml

<Window x:Class="TestProject.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="800"
    Height="600"
    Title="x:Code 엘리먼트 : XAML 파일에서 코드 내장하기"
    FontFamily="나눔고딕코딩"
    FontSize="16"
    Loaded="Window_Loaded">
    <StackPanel
        HorizontalAlignment="Center"
        VerticalAlignment="Center">
        <Button
            HorizontalAlignment="Center"
            Margin="10"
            Width="100"
            Height="30"
            Content="테스트"
            Click="button_Click" />
        <Ellipse Name="ellipse"
            Margin="10"
            Width="200"
            Height="200"
            Stroke="Red"
            StrokeThickness="10" />
        <ListBox Name="listBox"
            Margin="10"
            Width="150"
            Height="150"
            SelectionChanged="listBox_SelectionChanged" />
        <x:Code>
<![CDATA[

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    foreach(System.Reflection.PropertyInfo propertyInfo in typeof(Brushes).GetProperties())
    {
        this.listBox.Items.Add(propertyInfo.Name);
    }
}

private void button_Click(object sender, RoutedEventArgs e)
{
    Button button = sender as Button;

    MessageBox.Show($"{button.Content} 버튼을 클릭했습니다.");
}

private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    string item = this.listBox.SelectedItem as string;

    System.Reflection.PropertyInfo property = typeof(Brushes).GetProperty(item);

    this.ellipse.Fill = (Brush)property.GetValue(null, null);
}

]]>
        </x:Code>
    </StackPanel>
</Window>
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요