첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

■ DataTemplate 엘리먼트 : Triggers 속성을 사용해 DataTrigger 사용하기

----------------------------------------------------------------------------------------------------

<Window

    x:Class="TestProject.MainWindow"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="리스트 박스 테스트"

    Width="600"

    Height="450"

    Loaded="mainWindow_Loaded">

    <Grid>

        <ListBox Name="listBox"

            Width="200"

            Height="300"

            SelectionMode="Single">

            <ListBox.ItemTemplate>

                <DataTemplate>

                    <StackPanel Orientation="Horizontal">

                        <Image Name="itemImage"

                            Margin="0 0 5 0"

                            Width="16"

                            Height="16"

                            VerticalAlignment="Center"

                            Stretch="None"

                            Source="{Binding Icon}" />

                        <TextBlock                            

                            VerticalAlignment="Center"

                            Text="{Binding Text}" />

                    </StackPanel>

                    <DataTemplate.Triggers>

                        <DataTrigger Binding="{Binding Icon}" Value="{x:Null}">

                            <Setter TargetName="itemImage" Property="Visibility" Value="Collapsed" />

                        </DataTrigger>

                    </DataTemplate.Triggers>

                </DataTemplate>            

            </ListBox.ItemTemplate>            

        </ListBox>

    </Grid>

</Window>

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요