带有复选框和图像的ListBox(禁用/启用ListBox的默认选择行为)

时间:2014-11-19 05:48:19

标签: wpf xaml

我有一个带Checkbox的ListBox,旁边有一个Image。 在第一阶段: 第1步:我想只启用复选框以进行多个图像选择。 在第二阶段: 第2步:我们想隐藏复选框(一旦完成第1步) 并通过单击图像本身来完成下一个单个图像的选择。

我该如何进一步继续?

以下是代码:

<DataTemplate x:Key="listboxImageDataTemplate">
        <Grid Height="Auto" Width="Auto" Visibility="Visible" 
                            VerticalAlignment="Top" HorizontalAlignment="Left" 
                            Margin="3">

            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Grid Grid.Column="0">
                <CheckBox x:Name="selectCheckBox" Grid.Column="0"
                            VerticalContentAlignment="Center"
                            IsChecked="{Binding IsSelected}" 
                            HorizontalAlignment="Center" Margin="2">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Checked">
                            <i:InvokeCommandAction CommandParameter="{Binding PatientImageId}" 
                            Command="{Binding DataContext.OnCheckedCommand,ElementName= filteredImagesListBox}" />
                        </i:EventTrigger>
                        <i:EventTrigger EventName="Unchecked">
                            <i:InvokeCommandAction CommandParameter="{Binding PatientImageId}" 
                            Command="{Binding DataContext.OnUnCheckedCommand,ElementName= filteredImagesListBox}" />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </CheckBox>
            </Grid>
            <Grid Grid.Column="1">               
                <Label Content="{Binding ImageLabel}" Margin="2,4.7,52.017,102.5" 
                VerticalAlignment="Stretch" FontSize="10.667" FontWeight="Normal" HorizontalAlignment="Stretch" />        
                <Image  Margin="0,20,0,0" Source="{Binding ThumbNailImage}" Stretch="Fill" VerticalAlignment="Top" />              
            </Grid>
        </Grid>
</DataTemplate>
....
....
<ListBox Grid.Row="4" x:Name="filteredImagesListBox" ItemTemplate="{StaticResource listboxImageDataTemplate}" 
                        ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type UserControl}},
                                            Path=DataContext.CurrentVisitImageCollection}"
                        SelectedItem="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type UserControl}},
                                            Path=DataContext.SelectedImageForMarking}">
</ListBox>

0 个答案:

没有答案