0

If there are two prism regions defined in a shell, which one is on top is determined by how these are layed out in the shell one below the other.

<Grid Grid.Row="1" x:Name="_redGrid" >
    <ContentControl prism:RegionManager.RegionName="RedRegion" />
</Grid>
<Grid Grid.Row="1" x:Name="_greenGrid">
    <ContentControl prism:RegionManager.RegionName="GreenRegion" />
</Grid>

For a simple example, you can take a look at this. It has got a red view and a green view. When you run, it will look like the following.

Prism Region ZIndex

Is there a way to change this dynamically? Set the zindex of the prism region at run time?

I have extended the above example with a button, objective here is to click the button and change the top to bottom. You can see this example here.

I could do this in the backend file with brute force as follows.

private void btn1_Click(object sender, RoutedEventArgs e)
{
    _mainGrid.Children.Remove(_redGrid);
    _mainGrid.Children.Remove(_greenGrid);

    if (_toggleRegion)
    {
        _mainGrid.Children.Add(_redGrid);
        _mainGrid.Children.Add(_greenGrid);
    }
    else
    {
        _mainGrid.Children.Add(_greenGrid);
        _mainGrid.Children.Add(_redGrid);
    }
    _toggleRegion = !_toggleRegion;
}

wpf prism region zindex with button1

Click the button, and now the red is on top.

wpf prism region zindex with button2

So whats the best way to do this? Is there a feature in Prism which can accomplish this?

VivekDev
  • 20,868
  • 27
  • 132
  • 202
  • https://stackoverflow.com/questions/20094407/how-to-set-canvas-zindex-wpf-button-control-in-click-event – ASh Jan 12 '23 at 16:06

0 Answers0