【问题标题】:How do I add a Label over a ListBox in WPF?如何在 WPF 中的 ListBox 上添加标签?
【发布时间】:2018-06-06 08:05:01
【问题描述】:

我目前在DockPanel 中有一个ListBox(代表精彩的 Diaballik 游戏),最后我希望能够在由图片中的盒子:

<DockPanel>
    <ListBox DockPanel.Dock="Top" ItemsSource="{Binding Cases}"  SelectedItem="{Binding SelectedCase, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Top" SnapsToDevicePixels="True">

        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <UniformGrid Columns="{Binding Size}"/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>

        <ListBox.ItemContainerStyle>
            <Style TargetType="ListBoxItem">
                <Setter Property="Padding" Value="0"/>
            </Style>
        </ListBox.ItemContainerStyle>

        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid >
                    <Ellipse Fill="{Binding Color}" Width="50" Height="50" Visibility="{Binding HasPawn, Converter={StaticResource bool2visibility}}"/>                        
                    ...
                 </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

    <Label Content="VICTORY" />  <!-- How can this go over the list box ?  -->
</DockPanel>

【问题讨论】:

    标签: c# wpf xaml listbox label


    【解决方案1】:

    你可以做这样的事情(Grid 的行为是它只会将项目“堆叠”在彼此的“顶部”):

    <DockPanel>
        <Grid DockPanel.Dock="Top">
            <ListBox ItemsSource="{Binding Cases}" SelectedItem="{Binding SelectedCase, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Top" SnapsToDevicePixels="True">
    
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <UniformGrid Columns="{Binding Size}"/>
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
    
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="Padding" Value="0"/>
                    </Style>
                </ListBox.ItemContainerStyle>
    
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid >
                            <Ellipse Fill="{Binding Color}" Width="50" Height="50" Visibility="{Binding HasPawn, Converter={StaticResource bool2visibility}}"/>                        
                            ...
                         </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
    
            <Label Content="VICTORY" HorizontalAlignment="Center" VerticalAlignment="Center" />  <!-- How can this go over the list box ?  -->
        </Grid>
    </DockPanel>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-29
      • 1970-01-01
      • 2015-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多