c#wpf listview复选框项目

时间:2018-11-29 14:33:15

标签: c# wpf listview checkbox

我实现了用于照片预览的Listview。

<xctk:MaterialListBox InkEffectBrush="CornflowerBlue"  IsInkEffectActive="True" Background="Transparent" x:Name="TvBox" ScrollBar.Scroll="TvBox_Scroll" ScrollViewer.ScrollChanged="TvBox_ScrollChanged" GiveFeedback="TvBox_GiveFeedback"  AllowDrop="False" PreviewMouseLeftButtonDown="TvBox_PreviewMouseLeftButtonDown" PreviewMouseMove="TvBox_PreviewMouseMove" Margin="0,0,0,10" HorizontalAlignment="Stretch">
            <xctk:MaterialListBox.ItemContainerStyle>
                <Style TargetType="{x:Type xctk:MaterialListBoxItem}">
                    <Setter Property="Height" Value="100" />
                    <Setter Property="VerticalAlignment" Value="Top" />
                </Style>
            </xctk:MaterialListBox.ItemContainerStyle>
            <xctk:MaterialListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <UniformGrid Columns="4" Background="#00FFFFFF"/>
                </ItemsPanelTemplate>
            </xctk:MaterialListBox.ItemsPanel>
            <xctk:MaterialListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical" >
                        <Image Height="100" Width="200" Source="{Binding ImageData}"  Stretch="Uniform" />
                        <xctk:MaterialCheckBox Background="BlueViolet" Content="Выбрать" Click="MaterialButton_Click" HorizontalAlignment="Center" Height="35" Margin="0,20" Width="130"/>
                    </StackPanel>
                </DataTemplate>
            </xctk:MaterialListBox.ItemTemplate>
        </xctk:MaterialListBox> 

Screnshoot Listview. 我需要在图像上方选择一个复选框。 Example as needed 提示请解决此问题。预先谢谢你。

2 个答案:

答案 0 :(得分:1)

看看Canvas Panel

您应该能够将Image和Checkbox都放入画布面板中,并相应地设置其Top Left和ZIndex属性

答案 1 :(得分:1)

您正在使用StackPanel合并到控件。 StackPanel是用来在其中堆叠控件的,因此即使您使用Zindex,它们也不会相互重叠。

我先使用网格,然后再使用Panel.ZIndex来使控件重叠,并使用margin在图像上相应地设置复选框。

      <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <Image Panel.ZIndex="1"  Height="100" Width="200"  Source="Koala.jpg"  Stretch="Uniform" >
                    </Image>
                    <CheckBox Panel.ZIndex="2"  Background="BlueViolet" Content="Выбрать"   Margin="0,20" HorizontalAlignment="Center" Height="35" Width="130">
                    </CheckBox>

                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>