728x90
반응형
728x170
▶ 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
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] XmlnsDefinitionAttribute 클래스 : XmlNamsapce/ClrNamespace 속성을 사용해 XML 네임스페이스와 CLR 네임스페이스 매핑하기 (0) | 2020.08.21 |
---|---|
[C#/WPF] Frame 엘리먼트 : Source 속성을 사용해 리소스 형태의 XAML 파일 로드하기 (0) | 2020.08.20 |
[C#/WPF] Frame 클래스 : Source 속성을 사용해 리소스 형태의 XAML 파일 로드하기 (0) | 2020.08.20 |
[C#/WPF] XamlReader 클래스 : Load 정적 메소드를 사용해 리소스 형태의 XAML 파일 로드하기 (0) | 2020.08.20 |
[C#/WPF] Frame 엘리먼트 : NavigationUIVisibility 속성 사용하기 (0) | 2020.08.20 |
[C#/WPF] XAML 문자열에서 객체 생성하기 (0) | 2020.08.20 |
[C#/WPF] KeyGesture 클래스 : 단축 키 사용하기 (0) | 2020.08.19 |
[C#/WPF] DocumentPaginator 클래스 : 일반 텍스트 문자열 출력하기 (0) | 2020.08.19 |
[C#/WPF] TextBox 클래스 : GetLineIndexFromCharacterIndex/GetCharacterIndexFromLineIndex 메소드를 사용해 행/열 인덱스 구하기 (0) | 2020.08.19 |
[C#/WPF] FontStretchConverter 클래스 : ConvertToString/ConvertFromString 메소드 사용하기 (0) | 2020.08.19 |
댓글을 달아 주세요