첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
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
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요