0

enter image description here

I am new to C# WPF, I have created a Popup window which contains a DataGrid to hold some data. In certain cases if there are any errors in the data I want to display this error in the same popup window at the bottom of the window (See screenshot). The idea is that the user can then click ok and the message will disappear displaying the full datagrid again.

Does anybody know how to do this?

I do not want another popup message box in a separate window, I want all messages to be displayed/stacked in the same pop window as the datagrid.

NoName
  • 7,940
  • 13
  • 56
  • 108
edb500
  • 313
  • 1
  • 3
  • 14
  • following link will help you in overlapping message contaainer http://stackoverflow.com/questions/5450985/how-to-make-overlay-control-above-all-other-controls then hide the container by `visibility="collapsed"` on button click – Shaminder Singh Feb 26 '16 at 11:54

1 Answers1

0

Below, there are 2 grids in the XAML: There is is the master grid, which contains the DataGrid, and another grid which contains the error UI. The error grid is normally collapsed (Visibility set to Visibility.Collapsed).

When the error message needs to be shown, the error grid's Visibility is set to Visibility.Visible, which shows the grid. When the user clicks on the "Dismiss" button, the error grid's Visibility is set to Visibility.Collapsed.

There is not a separate window or popup. Everything is contained within the master view.

XAML:

  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition/>
      <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>
    <DataGrid>
    </DataGrid>
    <Button Grid.Column="1" Content="Show Message Window" VerticalAlignment="Center" Click="Button_Click_1"/>
    <!-- This is the "error grid"-->
    <Grid VerticalAlignment="Bottom" Height="Auto" 
       Background="AliceBlue" Visibility="Collapsed" Name="grdError">
      <TextBlock Text="Oops.  This is an error!"/>
      <Button Content="Dismiss" HorizontalAlignment="Right" Click="Button_Click_3"/>
    </Grid>
  </Grid>

Code Behind:

  public partial class MainWindow : Window
  {
    public MainWindow()
    {
      InitializeComponent();
    }

    private void Button_Click_1(object sender, RoutedEventArgs e)
    {
      grdError.Visibility = Visibility.Visible;
    }

    private void Button_Click_3(object sender, RoutedEventArgs e)
    {
      grdError.Visibility = Visibility.Collapsed;
    }
  }
CHendrix
  • 378
  • 2
  • 12