Search code examples
c#wpfxamlfrontend

How to make a window inside a blurred window in C# WPF?


This means when a blur is created on top of the main content of the program and a window is created above it with completely different content, inside the program. Like here:

Example of this concept #1 Example of this concept #2

I tried to create another window inside by writing it directly in xaml, as shown below, and technically it works, but I'm sure there is a much simpler way, and more universal, so that I don't have to write these * every time pop-ups* over and over again, like the example below. I searched for a long time but never found anything useful

An example of markup that can be simplified and optimized for different pages:

<!--MainContent1.xaml-->
<Grid x:Name="Main_Content1">
    <Border x:Name="popup_1" CornerRadius="5" Visibility="Hidden" Z.Index="0">
        <Grid>
            <!--Content of popup1-->
            <Button/>
            <Button/>
        </Grid>
    </Border>
    <Border x:Name="popup_2" CornerRadius="5" Visibility="Hidden" Z.Index="0">
        <Grid>
            <!--Content of popup2-->
            <Button/>
            <TextBlock/>
        </Grid>
    </Border>
    <Border x:Name="popup_3" CornerRadius="5" Visibility="Hidden" Z.Index="0">
        <Grid>
            <!--Content of popup3-->
            <TextBlock/>
        </Grid>
    </Border>
</Grid>

<!--MainContent2.xaml-->
<Grid x:Name="Main_Content2">
    <Border x:Name="popup_1" CornerRadius="5" Visibility="Hidden" Z.Index="0">
        <Grid>
            <!--Content of popup1-->
            <Button/>
            <Button/>
        </Grid>
    </Border>
</Grid>

<!--and other files-->

Solution

  • I researched this issue and came up with this template, which you can find on Github here

    This is my project in which the solution to this problem is described in detail, and it does not fit here completely

    (The original question was created in 4 January 2023, but for some reason it was deleted, so I created it again and answered because I found a solution and want to show it to others, otherwise why does this site exist?)