4

私はListBoxそこに見せるように宣言しました。重要なのは、アイテムの定義には、グリッドと要素を含むものがたくさんあるということです。アイテム内の1つの画像の表示を変更して、要素自体が選択されている場合にのみ表示されるようにします。

たとえば、アイテムが選択されたときに背景や全体的な外観を変更することができましたが、内部要素にアクセスできません:(

<ListBox stuff stuff stuff>
    <ListBox.ItemTemplate>
        <DataTemplate DataType="local:Patient">
            <grids , borders, things, stuff
                <Image Name="image1" source opacity stuff/>
            </ grids bordes and design in general>
        </DataTemplate>
    </ListBox.ItemTemplate>

    <ListBox.ItemContainerStyle>
        <Style TargetType="{x:Type ListBoxItem}">
            <Style.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="Foreground" Value="White"/>
                    <!--HERE I WANT TO CHANGE VISIBILITY OF THE IMAGE-->
                </Trigger>
            </Style.Triggers>
        </Style>
    </ListBox.ItemContainerStyle>

    <ListBox.Template>
        <!-- some other styles when deselected and other things -->
    </ListBox.Template>
</ListBox>

私は使ってみました:

<Setter TargetName="physiciansSettinsImage" Property="Visibility" Value="Visible"/>

ただし、スタイルセッターには設定できません。どんな手掛かり?

全体のデザインはかなり複雑なので、できるだけ再コーディングしないようにしたいと思います。

4

1 に答える 1

7

トリガーをに移動しDataTemplateます。

image1は_ VisibilityCollapsed

<DataTemplate.Triggers>
    <DataTrigger Binding="{Binding RelativeSource=
        {RelativeSource Mode=FindAncestor, AncestorType=
            {x:Type ListBoxItem}},Path=IsSelected}" Value="True">
        <Setter TargetName="image1" Property="Visibility" Value="Visible"/>
    </DataTrigger>
</DataTemplate.Triggers>

これで、アイテムが選択されると、Image's Visibilityに設定されますVisible

于 2013-03-26T15:18:34.413 に答える