Display control over other controls in a grid in WPF

I am developing a WPF application.
The main child controls are contained in a grid.
The bottom line contains the status bar.

The application should notify the user.
I want to programmatically display a notification in a user control in the lower right corner of the main window.
I want the notification notification user control to appear above the status bar and the control on the specified line.

How can I display the control with other controls contained in the grid?
Any help would be greatly appreciated.

+4
source share
4 answers

I solved my problem.
I changed the layout of the main XAML window.
I declared a custom notification control and a grid containing children of the main window in the same cell of the new grid.

I set some properties in the opening tag of the custom notification item:

  • Grid.ZIndex = "1"
  • HorizontalAlignment = "Right"
  • VerticalAlignment = "Bottom"
  • Margin = "0 0 20 20"

When a notification control is displayed:

  • The notification control is located above the grid containing the children of the main window.
  • The notification control is located in the lower right corner of the main window.
+1
source

The grid has the ZIndex property. Take a look at this example:

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" WindowTitle="ZIndex Sample">
  <Grid>

    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <Rectangle Grid.Row="0" Grid.ZIndex="3" Fill="blue"/>
    <Rectangle Grid.Row="0" Grid.ZIndex="1" Fill="yellow"/>
    <Rectangle Grid.Row="0" Grid.ZIndex="2" Fill="green"/>

    <!-- Reverse the order to illustrate z-index property -->

    <Rectangle Grid.Row="1" Grid.ZIndex="1" Fill="green"/>
    <Rectangle Grid.Row="1" Grid.ZIndex="3" Fill="yellow"/>
    <Rectangle Grid.Row="1" Grid.ZIndex="2" Fill="blue"/>

  </Grid>

ZIndex, , (, ).

+6

Popup ( ). IsOpen, .

 <Popup IsOpen="True">
                  <TextBlock Text="Important update!!" Background="White" Foreground="Black"></TextBlock>
                </Popup>

- -, ( ), . :

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"></RowDefinition>
        <RowDefinition Height="Auto"></RowDefinition>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"></ColumnDefinition>
        <ColumnDefinition Width="Auto"></ColumnDefinition>
    </Grid.ColumnDefinitions>

    <StackPanel Grid.Row="0" Grid.ColumnSpan="2">
        <!--Place any control here-->
    </StackPanel>
    <StackPanel x:Name="BottomRightPanel" Grid.Row="1" Grid.Column="1">
        <Popup IsOpen="True" Placement="">
            <TextBlock Text="Important update!!" Background="White" Foreground="Black"></TextBlock>
        </Popup>
    </StackPanel>
</Grid>
+3

,

Panel.ZIndex, .

enter image description here

<Expander Name="expander_options" Header="Options"  Margin="330,10,0,182" Panel.ZIndex="1">
            <StackPanel Margin="10,4,0,0" Panel.ZIndex="2" Background="Aqua">
                <CheckBox Margin="4" Content="Option 1" />
                <CheckBox Margin="4" Content="Option 2" />
                <CheckBox Margin="4" Content="Option 3" />
            </StackPanel>
        </Expander>
+3

Source: https://habr.com/ru/post/1538221/


All Articles