728x90
반응형
728x170
■ DataTemplate 엘리먼트를 사용해 ListBox 엘리먼트의 ItemTemplate 속성을 설정하는 방법을 보여준다.
▶ 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"
xmlns:local="clr-namespace:TestProject"
Width="800"
Height="600"
Title="DataTemplate 엘리먼트 : ListBox 엘리먼트의 ItemTemplate 속성 설정하기"
Background="{Binding ElementName=listBox, Path=SelectedValue}"
FontFamily="나눔고딕코딩"
FontSize="16">
<Window.Resources>
<DataTemplate x:Key="ListBoxItemDataTemplateKey" DataType="{x:Type local:NamedBrush}">
<StackPanel Orientation="Horizontal">
<Rectangle
Width="16"
Height="16"
Margin="2"
Stroke="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"
Fill="{Binding Path=Brush}" />
<TextBlock
VerticalAlignment="Center"
Text="{Binding Path=Name}" />
</StackPanel>
</DataTemplate>
</Window.Resources>
<ListBox Name="listBox"
ItemTemplate="{StaticResource ListBoxItemDataTemplateKey}"
ItemsSource="{x:Static local:NamedBrush.NamedBrushArray}"
Width="200"
Height="200"
HorizontalAlignment="Center"
VerticalAlignment="Center"
SelectedValuePath="Brush" />
</Window>
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] FormattedText 클래스 : SetForegroundBrush/SetFontWeight/SetFontStyle/SetFontSize 메소드 사용하기 (0) | 2020.08.27 |
---|---|
[C#/WPF] 지오메트리 디자이너 사용하기 (0) | 2020.08.27 |
[C#/WPF] xml:space 속성 : XAML에서 문자열 공백 유지하기 (0) | 2020.08.27 |
[C#/WPF] XmlDataProvider 엘리먼트 : x:XData 엘리먼트를 사용해 XML 데이터 내장하기 (0) | 2020.08.26 |
[C#/WPF] ItemsPanelTemplate 엘리먼트 : ListBox 엘리먼트의 ItemPanel 속성에 커스텀 패널 설정하기 (0) | 2020.08.26 |
[C#/WPF] DataTemplate 엘리먼트 : Button 엘리먼트의 ContentTemplate 속성 설정하기 (0) | 2020.08.26 |
[C#/WPF] ControlTemplate 엘리먼트 : CheckBox 엘리먼트 정의하기 (0) | 2020.08.26 |
[C#/WPF] ControlTemplate 엘리먼트 : RadioButton 엘리먼트 정의하기 (0) | 2020.08.26 |
[C#/WPF] 지오메트리 사용하기 (0) | 2020.08.26 |
[C#/WPF] ControlTemplate 엘리먼트 : RadioButton 엘리먼트 정의하기 (0) | 2020.08.25 |
댓글을 달아 주세요