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

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

<DataTemplate>

    <StackPanel

        Margin="1"

        Orientation="Horizontal">

        <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.Triggers>

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

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

        </DataTrigger>

    </DataTemplate.Triggers>

</DataTemplate>

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

Posted by 사용자 icodebroker