如何在WPF中的ListBox上添加标签?

时间:2017-12-24 16:37:13

标签: c# wpf xaml listbox label

我目前在ListBox中有一个DockPanel(代表一个精彩的Diaballik游戏),最后我希望能够显示一个标签 Victory 框中的网格如图所示:

enter image description here

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

1 个答案:

答案 0 :(得分:1)

你可以做这样的事情(<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> 的行为是这样的,它只会&#34;堆叠&#34;项目&#34;在彼此的顶部&#34;:< / p>

DELETE