WPF [SOLVED]: How do I add a Label over a ListBox in WPF?

WPF [SOLVED]: How do I add a Label over a ListBox in WPF?

Home Forums Frameworks WPF WPF [SOLVED]: How do I add a Label over a ListBox in WPF?

Tagged: , , , ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #246880

    Cloudy Point
    Keymaster

    QuestionQuestion

    I have currently a ListBox in a DockPanel (that represents a wonderful Diaballik game) and at the end I want to be able to show up a label Victory over the grid made by the boxes like in the picture :

    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>
    

    #246881

    Cloudy Point
    Keymaster

    Accepted AnswerAnswer

    You could do something like this (the behaviour of a Grid is such that it will just “stack” the items “on top” of each other):

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

    Source: https://stackoverflow.com/questions/47962332/how-do-i-add-a-label-over-a-listbox-in-wpf
    Author: Chris Mack
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.