728x90
반응형
728x170
■ DataTemplate 엘리먼트에서 대상 엘리먼트 속성을 바인딩하는 방법을 보여준다.
▶ 예제 코드 (XAML)
<ListBox x:Class="TestProject.MultiListBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignWidth="200"
d:DesignHeight="200"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
SelectionMode="Extended">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel
Margin="1"
Orientation="Horizontal">
<CheckBox Name="itemCheckBox"
VerticalAlignment="Center"
Width="20"
IsChecked="{Binding IsChecked}" />
<Image Name="itemImage"
VerticalAlignment="Center"
Margin="0 0 5 0"
Width="16"
Height="16"
Stretch="None"
Source="{Binding Icon}" />
<TextBlock Name="itemTextBlock"
VerticalAlignment="Center"
Margin="0"
Width="{Binding RelativeSource={RelativeSource AncestorType=ListBox, Mode=FindAncestor}, Path=ActualWidth}"
Text="{Binding Text}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] Button 클래스 : 코드로 클릭 이벤트 발생시키기 (0) | 2015.09.18 |
---|---|
[C#/WPF] Binding 태그 확장 : Source 속성에서 x:Static 태그 확장을 사용해 정적 객체 속성 바인딩하기 (0) | 2015.09.18 |
[C#/WPF] Trigger 엘리먼트 : Property 속성을 사용해 컨트롤 템플리트 트리거에서 해당 엘리먼트에서 정의한 속성 설정하기 (0) | 2015.09.18 |
[C#/WPF] DataTemplate 엘리먼트 : Triggers 속성 사용하기 (0) | 2015.09.18 |
[C#/WPF] Binding 태그 확장 : RelativeSource 속성에서 RelativeSource 태그 확장의 AncestorType 속성을 사용해 부모 엘리먼트 속성 바인딩하기 (0) | 2015.09.18 |
[C#/WPF] ToolBar 클래스 : 오버플로우 패널 숨기기 (0) | 2015.09.17 |
[C#/WPF] 컨트롤 템플리트에서 컨트롤 객체 구하기 (0) | 2015.09.14 |
[C#/WPF] Point 구조체 : 회전하기 (0) | 2015.09.14 |
[C#/WPF] Viewbox 엘리먼트 사용하기 (0) | 2015.09.10 |
[C#/WPF] 문자열 배열 리소스 사용하기 (0) | 2015.09.05 |
댓글을 달아 주세요