【问题标题】:c# wpf listview checkbox itemc# wpf listview复选框项目
【发布时间】:2018-11-30 01:04:32
【问题描述】:

我实现了 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> 

我需要图像顶部的复选框。 提示请解决这个问题。提前谢谢你。

【问题讨论】:

  • 是否涉及MaterialDesign
  • @satish-pai 我将 Xceed Toolkit Plus 用于 WPF,但使用通常的复选框的实现也适合。谢谢。
  • 检查我的回答是否符合你的要求。

标签: c# wpf listview checkbox


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    看看Canvas Panel

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-02
      • 2015-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多